<ke***********@googlemail.comwrote in message
news:11**********************@o61g2000hsh.googlegr oups.com...
On 25 Jun, 18:17, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
><kelvin.koo...@googlemail.comwrote in message
news:11**********************@k79g2000hse.googleg roups.com...
>I have an unmanaged DLL which calls my managed C++ app using a
callback (standard C++ function pointer). I can receive the callbacks
OK using a static function with global scope, but I can't find a way
to get hold of a pointer to my Form to pass it the data.
In the unmanaged world, a callback (almost) always comes with a extra
parameter to pass application data.
.NET can also make a bound delegate into a function pointer.
If you show the declaration of the callback and the line used to register
it, we can probably help more.
Definition of callback
typedef void (*CallbackFn)(BYTE*, int);
Function to register callback
Initialise(const char *pPort, CallbackFn callback);
Note this is C++ not C.
Then Initialise is a member function of some class? Does pPort get passed
to the callback as its first parameter?
If not, you'll need a .NET bound delegate created in the usual way, and use
::System::Runtime::InteropServices::Marshal::GetFu nctionPointerForDelegate
to get an unmanaged function pointer from it.
>
KK