简体   繁体   中英

Pointer to function for unmanaged code in C#

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 struct?

    [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);

也许Marshal.GetFunctionPointerForDelegate方法可以帮助你。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM