I have a callback *inside* a C DLL (static void __stdcall) . I want another program to register it as such (by passing it the func ptr) and then call the calback inside the DLL. I have had no luck so far. However, the same callback works if its inside a regular C++ program. I am now wondering if having callbacks in a DLL is even possible. Any help will be appreciated!
Adding some code:
public static extern void DLL_SetCallback(CallbackDelegate pfn);
public delegate void CallbackDelegate();
//setDelegate() is called in init() of the C# app
public void setDelegate()
CallbackDelegate CallbackDelegateInstance = new CallbackDelegate(callback);
public void callback()
//This is the function which will be called by the DLL
MessageBox.Show("Called from the DLL..");
//is linked to externalLibrary.lib
typedef void (__stdcall CallbackFunc)(void);
CallbackFunc* func; //global in DLL
extern "C" __declspec(dllexport) void DLL_SetCallback(CallbackFunc* funcptr)
//setting the function pointer
func = funcptr;
extern "C" __declspec(dllexport) void RegisterEventHandler(Target, Stream,&ProcessEvent , NULL)
//ProcessEvent is func to be caled by 3rd party callback
//Call third-party function to register &ProcessEvent func-ptr (succeeds)
//This is the function which never gets called from the 3rd party callback
//But gets called when all the code in the DLL is moved to a standard C program.
void __stdcall ProcessEvent (params..)
//Do some work..
func(); //Call the C# callback now
Please tell us what happens. Does it fail to link? to compile? Crashes?
以上就是callbacks inside a DLL?的详细内容，更多请关注web前端其它相关文章！