Home > Net >  Difficult, C # call C library function, the structure of the library function function, this how ref
Difficult, C # call C library function, the structure of the library function function, this how ref

Time:11-20

//an apology first, only 85 points, for a long time to come, 
//the following is a c + + header file
//callback function definition; Each callback function is a return to an event,
Typedef struct {
//command sent successfully, the target device response,
Void (* PTK_UserCommandSuccessful) (const void * sender, uint receid, uchar hostid, uchar terid, uchar commandcode);
Send failure//command, the destination no response,
Void (* PTK_UserCommandDelete) (const void * sender, uint receid, uchar hostid, uchar terid, uchar commandcode);
//alarm message
Void (* PTK_Alarm_Information) (const void * sender, uint receid, uchar hostid, uchar terid, uchar areaid, EPTK_Alarm_Event Eventcode);
//keyboard display to be the host of V3.3 above only response
Void (* PTK_Alarm_KpdDisplay) (const void * sender, uint receid, uchar hostid, uchar * Dis1, uchar * Dis2);
} SPTK_callbackFun;

//DLL initialization function: complete memory allocation, thread open operation, such as to obtain the corresponding system resources fully,
PTKALARMLIB_API void * Init_PTKAlarmlib (const void * sender, SPTK_callbackFun * CallBack);


@ moderator

CodePudding user response:

CodePudding user response:

The c # code is written, but it won't work, x86 also set,
//callback function definition; Each callback function is a return to an event, 
[StructLayout (LayoutKind. Sequential)]
Public struct SPTK_callbackFun {
[DllImport (" AlarmSDK. DLL, "EntryPoint=" PTK_UserCommandSuccessful CallingConvention=CallingConvention. StdCall)]
Public static extern IntPtr PTK_UserCommandSuccessful (ref byte sender, System. UInt16 receid, int hostid, int terid, int commandcode);

[DllImport (" AlarmSDK. DLL, "EntryPoint=" PTK_UserCommandDelete CallingConvention=CallingConvention. StdCall)]
Public static extern IntPtr PTK_UserCommandDelete (ref byte sender, System. UInt16 receid, int hostid, int terid, int commandcode);

[DllImport (" AlarmSDK. DLL, "EntryPoint=" PTK_Alarm_Information CallingConvention=CallingConvention. StdCall)]
Public static extern IntPtr PTK_Alarm_Information (ref byte sender, System. UInt16 receid, int hostid, int terid, int areaid, EPTK_Alarm_Event Eventcode);

[DllImport (" AlarmSDK. DLL, "EntryPoint=" PTK_Alarm_KpdDisplay CallingConvention=CallingConvention. StdCall)]
Public static extern IntPtr PTK_Alarm_KpdDisplay (ref byte sender, System. UInt16 receid, int hostid, int Dis1, int Dis2);
}

//PTKALARMLIB_API void * Init_PTKAlarmlib (const void * sender, SPTK_callbackFun * CallBack);
[DllImport (" AlarmSDK. DLL, "EntryPoint=" Init_PTKAlarmlib CallingConvention=CallingConvention. StdCall)]
Public static extern IntPtr P_Client_QueryRecord (ref byte zero, ref SPTK_callbackFun pInfo);

CodePudding user response:

CodePudding user response:

You look a lot all the definition of
First of all, uint and uchar you need to view the file is how to define, it is to determine the corresponding type, just from the name like unsigned 32 and unsigned 8,
Second, the structure inside is the callback function, the corresponding should be commissioned,
Should be like this
 
//this assumes
//uint=unsigned int=unsigned 32=c # uint
//uchar=unsigned char=8=c # byte unsigned
//actually you need according to the actual definition of c + + file view and then converted to the corresponding c # type
Public delegate void _PTK_UserCommandSuccessful (System. IntPrt sender, uint receid, byte hostid, byte terid, byte commandcode);
//the rest of the ellipsis...

[StructLayout (LayoutKind. Sequential)]
Public struct SPTK_callbackFun {
Public _PTK_UserCommandSuccessful PTK_UserCommandSuccessful;
//the rest of the ellipsis...
}


CodePudding user response:

1. Basic types to correct the corresponding
2. The StructLayout feature supports three additional fields: CharSet, Pack, Size
Need to display definition, a corresponding will not result in any error
3. The callback function need to entrust to the corresponding


CodePudding user response:

Data type is the structure I haven't tried, your side of the c + + code the type of data structure, c # here to also should be structure, and you have not qualitative pointer, c + + side need to c + + code posted can decide c # here how the incoming data

CodePudding user response:

Alarm information conversion, several other transformation about
 

///the Return Type: void
///sender: void *
///receid: int
///hostid: char
///terid: char
///commandcode: char
Public delegate void _PTK_UserCommandSuccessful (System. IntPtr sender, int receid, byte hostid, byte terid, byte commandcode);

///the Return Type: void
///sender: void *
///receid: int
///hostid: char
///terid: char
///commandcode: char
Public delegate void _PTK_UserCommandDelete (System. IntPtr sender, int receid, byte hostid, byte terid, byte commandcode);

///the Return Type: void
///sender: void *
///receid: int
///hostid: char
///Dis1: char *
///Dis2: char *
Public delegate void _PTK_Alarm_KpdDisplay (System. IntPtr sender, int receid, byte hostid, System. IntPtr Dis1, System. IntPtr Dis2);

[System. The Runtime. InteropServices. StructLayoutAttribute (System. The Runtime. InteropServices. LayoutKind. Sequential)]
Public struct SPTK_callbackFun {

///_PTK_UserCommandSuccessful
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related