C# P/Invoke structure problem

后端 未结 4 501
[愿得一人]
[愿得一人] 2021-01-12 18:55

I am trying to write a C# P/Invoke wrapper for a C API (a native Win dll), and generally this is working fine. The only exception is a specific method which takes a struct a

4条回答
  •  别那么骄傲
    2021-01-12 19:01

    Looks to me like the problem is that you're passing a reference by reference. Since MSTrackData is a class (i.e. reference type), passing it by reference is like passing a pointer-to-pointer.

    Change your managed prototype to:

    public static extern bool EncodeMagstripe(IntPtr hDC,
                        MSTrackData pTrack1,
                        MSTrackData pTrack2,
                        MSTrackData pTrack3,
                        MSTrackData reserved);
    

    See the MSDN article about passing structures.

提交回复
热议问题