.net - C3374: can't take address of 'function' unless creating delegate instance -
I'm having difficulty using the third party library registration function to file a callback. I am writing in C ++ CLI and reaching the library I wrote in C or C ++.
What does the above compiler error mean?
This is the registration function as defined by the vendor:
MYCO int WINAPI MyCo_Device_Register_CallbackFunc (LPVOID Funk, LPVOID LPPARM, DWWD Mask); This is a callback defined by the seller:
typingfiff zero (callback * MyCo_Device_CallbackProc) (DWORD DDTTAS, LPVOID LPPARM); My callback function: Public ref class device {zero callbackfunk }
My call (which fails):
MyCo_Device_Register_CallbackFunc ((LPVOD) device: CallbackFunk, NLTP, 0xFFFF);
If I was guessed, then you are trying to find out Pass a managed function and pass it as a natively function pointer, it will not work at all. Either write a native bridge (hard and maybe no use), or (and this is the easiest way), make a representative and do not forget that the rep will have to survive for that period to call back the original code Hopefully, so you have to place it somewhere else.
Oh, and all functions or price squares within a ref class are managed tasks, if it was not clear.
[edit] Expand the answers to cover the questions in the comments. The first step is to create a Match Representative for the function you provide, it is going to look like this:
Public representative Zero CallbackFunkDeliget (Dedworld's DDStatus, LPVOID LPPARM); Then, you will need to create one:
callbackfeng delegate del = gcnu callback function (callbackfank); And as mentioned before, you should store it in your class as a member to ensure that your membership does not end. Finally, you need to get the function pointer and pass it down:
MyCo_Device_Register_CallbackFunc ((MyCo_Device_CallbackProc) Marshall :: GetFunctionPointerForDelegate (del). ToPointer (), 0, 0); I think everything covers everything you need, namespace system; And you should be right.
Comments
Post a Comment