Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You'll probably want to use <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.getdelegateforfunctionpointer.aspx" rel="noreferrer"><code>Marshal.GetDelegateForFunctionPointer</code></a>:</p> <ol> <li>Create a delegate type that matches the signature of the native function, keeping in mind the right way to marshal types and using <a href="http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute.aspx" rel="noreferrer"><code>MarshalAs</code></a> as needed</li> <li>Communicate the native function pointer from your native code to your C# code however you can (in your case, it looks like you can use your COM -> C# connection)</li> <li>Use <code>Marshal.GetDelegateForFunctionPointer</code> to turn the pointer into a C#-callable delegate</li> <li>Invoke the delegate with your parameters</li> </ol> <p>Junfeng Zhang has an example of doing this <a href="http://blogs.msdn.com/b/junfeng/archive/2004/07/14/181932.aspx" rel="noreferrer">here</a>.</p> <p>Note the restrictions mentioned on MSDN:</p> <blockquote> <p>The GetDelegateForFunctionPointer method has the following restrictions:</p> <ul> <li>Generics are not supported in interop scenarios.</li> <li>You cannot pass an invalid function pointer to this method.</li> <li>You can use this method only for pure unmanaged function pointers.</li> <li>You cannot use this method with function pointers obtained through C++ or from the GetFunctionPointer method.</li> <li>You cannot use this method to create a delegate from a function pointer to another managed delegate.</li> </ul> </blockquote> <p>The part about C++ is likely referring to function pointers for class methods. This should still work for global functions. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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