Hi,
I've got a third party c dll that I'm trying to make function calls to from c#. I'm using pinvoke to do this, but I'm new to c#, so I'm not sure if I'm doing this right. One of the function calls from c# passes a callback function to and i'm not sure how to implement this. Here's the code
[c]
//QueAPI.dll
typedef uint16 QueErrT16; enum
{
queErrNone = 0, /* Success */
queErrNotOpen = 1, /* Close() without having called open() first */
queErrBadArg, /* Invalid parameter passed to function */
queErrMemory, /* Out of memory */
queErrNoData, /* No data available */
queErrAlreadyOpen, /* The Que API is already open */
queErrInvalidVersion, /* The Que API is an incompatable version */
queErrComm, /* There was an error communicating with the API */
queErrCmndUnavail, /* The command is unavaialbe */
queErrStillOpen, /* Library is still open */
queErrFail, /* General failure */
queErrCancel /* Action cancelled by user */
};
typedef uint8 QueNotificationT8; enum
{
queLocationChange = 0, /* The GPS position has changed */
queStatusChange = 1, /* The GPS status has changed */
queLostFix = 2, /* The quality of the GPS position computation
has become less than two dimensional */
queSatDataChange = 3, /* The GPS satellite data has changed */
queModeChange = 4, /* The GPS mode has changed */
queEvent = 5, /* An event has occurred (i.e. sunrise/set,
route has started/ended, etc. ) */
queCPOPositionChange = 6, /* The GPS CPO position data has been updated */
queSatelliteInstChange = 7, /* THe GPS CPO satellite data has been updated */
queUserNotificationCount, /* Count of change type enumerations(user only) */
// Internal notifications (do not publish, not visible to end user)
quePickPointComplete, /* The user has picked a position. */
queNotificationCount, /* Count of change type enumerations (all) */
queInvalid = 0xFF, /* Invalid message. Ignore */
};
typedef void (__stdcall* QueNotificationCallback)( QueNotificationT8 );
__declspec(dllexport) QueErrT16 QueAPIOpen( QueNotificationCallback callback );
[c#]
//QueAPI.cs
public enum QueErrT16
{
queErrNone = 0, /* Success */
queErrNotOpen = 1, /* Close() without having called open() first */
queErrBadArg, /* Invalid parameter passed to function */
queErrMemory, /* Out of memory */
queErrNoData, /* No data available */
queErrAlreadyOpen, /* The Que API is already open */
queErrInvalidVersion, /* The Que API is an incompatable version */
queErrComm, /* There was an error communicating with the API */
queErrCmndUnavail, /* The command is unavaialbe */
queErrStillOpen, /* Library is still open */
queErrFail, /* General failure */
queErrCancel /* Action cancelled by user */
}
public enum QueNotificationT8 : byte
{
queLocationChange = 0, /* The GPS position has changed */
queStatusChange = 1, /* The GPS status has changed */
queLostFix = 2, /* The quality of the GPS position computation
has become less than two dimensional */
queSatDataChange = 3, /* The GPS satellite data has changed */
queModeChange = 4, /* The GPS mode has changed */
queEvent = 5, /* An event has occurred (i.e. sunrise/set,
route has started/ended, etc. ) */
queCPOPositionChange = 6, /* The GPS CPO position data has been updated */
queSatelliteInstChange = 7, /* THe GPS CPO satellite data has been updated */
queUserNotificationCount, /* Count of change type enumerations(user only) */
// Internal notifications (do not publish, not visible to end user)
quePickPointComplete, /* The user has picked a position. */
queNotificationCount, /* Count of change type enumerations (all) */
queInvalid = 0xFF, /* Invalid message. Ignore */
}
//I don't know how to implement the call back function that QueNotificationCallback would call here.
[DllImport("QueAPI.dll")]
public static extern QueErrT16 QueAPIOpen(QueNotification
Callback callback);
So that's the code I'm working with. The QueAPIOpen function is what I'm trying to call from c# to the c dll.
Thanks