>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.
kelvin.koogan@googlemail.com - 26 Jun 2007 08:33 GMT
> <kelvin.koo...@googlemail.com> wrote in message
>
[quoted text clipped - 12 lines]
> 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.
KK
Ben Voigt [C++ MVP] - 26 Jun 2007 15:41 GMT
>> <kelvin.koo...@googlemail.com> wrote in message
>>
[quoted text clipped - 22 lines]
>
> 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::GetFunctionPointerForDelegate
to get an unmanaged function pointer from it.
> KK