开发者

Pointer to function for unmanaged code in C#

开发者 https://www.devze.com 2022-12-14 08:04 出处:网络
I have a dll which accepts a struct that contains a pointer to a function to do a callback. How can I get an IntPtr to a function of my application to build the 开发者_如何学Cstruct?

I have a dll which accepts a struct that contains a pointer to a function to do a callback.

How can I get an IntPtr to a function of my application to build the 开发者_如何学Cstruct?

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public class OPERATION {
        public uint OperationID;
        public IntPtr Context;  
        public IntPtr Callback; -> How to pass this?
    }

Here is the delegate accepting the OPERATION struct

public delegate void MY_CALLBACK([In] OPERATION operation, [In] uint msgId, [In] IntPtr msgDataPtr);


use Marshal.GetFunctionPointerForDelegate


Maybe the Marshal.GetFunctionPointerForDelegate method may help you.

0

精彩评论

暂无评论...
验证码 换一张
取 消