Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I had to wager a guess, you're trying to taken the address of a MANAGED function and pass it as a NATIVE function pointer. That won't work at all. Either write a native bridge (harder and probably no advantage), or (and this is the easier approach), create a delegate and use <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getfunctionpointerfordelegate.aspx" rel="noreferrer">Marshal.GetFunctionPointerForDelegate</a>. Don't forget that the delegate has to stay alive for the duration that the native code expects to call back, so you most likely need to store it somewhere.</p> <p>Oh, and all functions inside a ref class or value class are managed functions, in case that wasn't clear.</p> <p>[EDIT] Expanding answer to cover questions in comments. The first step is to create a matching delegate. For the function you provided, it's going to look like this:</p> <pre><code>public delegate void CallbackFuncDelegate(DWORD ddStatus, LPVOID lpParam); </code></pre> <p>Then, you'll need to create one:</p> <pre><code>CallbackFuncDelegate del = gcnew CallbackFuncDelegate(CallbackFunc); </code></pre> <p>And as noted previously, you should store that IN your class as a member in order to make sure it doesn't vanish. Lastly, you need to get the function pointer and pass it down:</p> <pre><code>MyCo_Device_Register_CallbackFunc((MyCo_Device_CallbackProc) Marshal::GetFunctionPointerForDelegate(del).ToPointer(), 0, 0); </code></pre> <p>I think that covers everything. All you need is using namespace System; and you should be fine.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload