Create a function in C# with the prototype equivalent to the callback you need to pass through QueAPIOpen.I think it must work.
Main Topics
Browse All TopicsHi,
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
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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: AlexFMPosted on 2005-06-01 at 22:26:09ID: 14128077
http://msdn.microsoft.com/ library/de fault.asp? url=/libra ry/ en-us/d ncscol/htm l/csharp09 192002.asp
See: Functions with Callbacks