Reputation: 603
WIN32 funciton to call from C#:
int PTSetGUICallbacks (
IN int hConnection,
IN void *pGuiStreamingCallbackCtx,
IN PT_GUI_STATE_CALLBACK pfnGuiStateCallback,
IN void *pGuiStateCallbackCtx
)
Win32 Callback function prototype "PT_GUI_STATE_CALLBACK":
int PT_STD_GUI_STATE_CALLBACK (
IN DWORD dwGuiState,
OUT BYTE *pbyResponse,
IN DWORD dwMessage
)
My C# function for to call the above Win32 function inside i am passing C# function as a callback to that Win32 function:
public void SetCallback()
{
var callback_delegate = new PT_GUI_STATE_CALLBACK(GUI_STATE_CALLBACK);
GCHandle gch = GCHandle.Alloc(callback_delegate);
IntPtr intptr_delegate =
Marshal.GetFunctionPointerForDelegate(callback_delegate);
int mErrorCode = PTSetGUICallbacks(mDevHandle, IntPtr.Zero, intptr_delegate, IntPtr.Zero);
gch.Free();
}
this code doesnot work, i mean i am not getting callback from win32 api to my C# method (GUI_STATE_CALLBACK
)
So now i need to pass that callback to the win32 api from my C# function.
Anyone know the answer?
PInvoke Function declaration for WIN32 api:
public static extern int PTSetGUICallbacks(int ahConnection,
IntPtr aStreamingcbCtx, IntPtr aGuiStateCb, IntPtr aGuiStateCbCtx);
Any update on this?
Is any other alternative way is there to do this?
Upvotes: 2
Views: 1620
Reputation: 139
Define your CallBack function as "CallBack"
public static extern int PTSetGUICallbacks(
int ahConnection,IntPtr aStreamingcbCtx,
CallBack aGuiStateCb, IntPtr aGuiStateCbCtx);
Calling it:
CallBack cb = new CallBack(GuiCBFunction);
PTSetGUICallbacks(mDevHandle, IntPtr.Zero, cb, IntPtr.Zero);
The Callback in c#:
int GuiCBFunction (UInt32 dwGuiState, IntPtr pbyResponse, UInt32 dwMessage )
example for "CallBack": http://msdn.microsoft.com/de-de/library/a95009h1%28v=vs.80%29.aspx
Upvotes: 1