I have a legacy unmanaged DLL function that expects to be passed a structure like this:
typedef struct tag_ACALLBACK
{
void *ncCallbackFunction;
void *ncUserData;
} ACALLBACK;
I'm stumped about how to assign a managed class method to the ncCallbackFunction function pointer.
I've tried creating a __delegate of the proper structure, but, as I half expected, you can't assign
a delegate to a void*:
IdleCallbackHandler* idleHandler = new IdleCallbackHandler(this, &MyClass::IdleCallback);
theSettings->nstIdle.ncCallbackFunction = idleHandler; // this fails
I've read about, and used, the marshaling/pinvoke capability to pass a delegate to an unmanaged
function that expects a function pointer, but how do I assign a delegate to a function pointer
member variable?
- Mark
Mattias Sj?gren - 21 Sep 2004 11:59 GMT
>I've read about, and used, the marshaling/pinvoke capability to pass a delegate to an unmanaged
>function that expects a function pointer, but how do I assign a delegate to a function pointer
>member variable?
Use the same technique here. Write a function that accepts and returns
a function pointer, and call it through P/Invoke passing in a
delegate. Assign the return value to the struct member.
In v2.0 there will be a better way.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.