Passing a C# callback function through Interop/pinvoke

前端 未结 2 1563
醉梦人生
醉梦人生 2020-12-01 08:16

I am writing a C# application which uses Interop services to access functions in a native C++ DLL. I am already using about 10 different functions which are working.

<
2条回答
  •  醉话见心
    2020-12-01 08:26

    Can you try changing the Func delegate to

        public delegate void Func([In, MarshalAs(UnmanagedType.LPStr)] string arg1, [In, MarshalAs(UnmanagedType.LPStr)] string arg2);
    

    And the SetFunc method to

    [DllImport("lib", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Winapi)]
    public static extern int SetFunc(Func lpfn);
    

提交回复
热议问题