Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Delegate not working...

Delegate not working...

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++debuggingquestion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Moody
    wrote on last edited by
    #1

    Hey guys, I'm trying to get a callback function to work from my unmanaged C++ dll. Everytime I run my program I get System.NullReferenceException saying "Object reference not set to an instance of an object." in mscorlib. This error is thrown when the runtime tries to execute the callback function in my unmanaged C++ DLL. What I'm trying to do is real simple and straightforward: namespace ProtocolDll { __delegate void MY_CALLBACK(); [DllImport("test.dll")] extern "C" void UnmanagedFunc(MY_CALLBACK __gc* myCallback); public __gc class Wrapper { public: void myCallback() { MY_CALLBACK* cb = new MY_CALLBACK(this,&Wrapper::CallMePlease); UnmanagedFunc(cb); // Call the unmanaged dll function } void CallMePlease() { Int32 i=0; i=i+1; // I put a breakpoint here but it never makes it }; } ************************************ Here is my unmanaged C++ dll code: typedef void (*MY_CALLBACK)(); EXPORT void UnmanagedFunc(MY_CALLBACK* pfnCallback); void UnmanagedFunc(MY_CALLBACK* pfnCallback) { (*pfnCallback)(); } Any idea what I am doing wrong? Thanks for any help... this is my last issue with this unmanaged dllimport stuff... this code is a bear to write. david

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups