callbacks inside a DLL?

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! Thanks. Adding some code: C# app: [DllImport("DLLfilename.dll")] 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); DLL_SetCallback(CallbackDelegateInstance); } public void callback() { //This is the function which will be called by the DLL MessageBox.Show("Called from the DLL.."); } C DLL: //is linked to externalLibrary.lib #include "externalLibrary.h" typedef void (__stdcall CallbackFunc)(void); CallbackFunc* func; //global in DLL //Exported extern "C" __declspec(dllexport) void DLL_SetCallback(CallbackFunc* funcptr) { //setting the function pointer func = funcptr; return; } //Exported 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) ... return; } //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 return; }
Please tell us what happens. Does it fail to link? to compile? Crashes?

以上就是callbacks inside a DLL?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏