Enable VB.Net callback function to be used by unmanaged C++ DLL
Posted on 2007-03-28
This is VB.Net Question:
I need to set up an asynchronous callback from a DLL (written in C++) to which I documentation for, but do not have visibility into its source code.
My application must first 'register' the callback function by sending the address of a delegate to the DLL. Once registered, the callback is intended to then be used one or more times until the application terminates, whenever the dll determines it needs to use it, or until I 'de-register' it (effectively my callback is intended to be an event handler like a 'mouse_click')
Question Part 1. How do I create the delegate or write the callback function inorder for the DLL to properly use my callback function?
Question Part 2. In -registering- my callback I use a separate delegate to enable my app to use the 'registration' function in the DLL. Isn't this (shouldn't it be) a straightforward use of a function in the DLL. IOWs, I can't see how the registering the callback function would be anything more a function call that does not need a delegate.
Obviously, I'm relatively new to callbacks (and delegates), explanations and code examples would be appreciated.