convert struct handle from managed into unmanaged C++/CLI

前端 未结 2 1504
生来不讨喜
生来不讨喜 2021-02-06 15:08

In C#, I defined a struct:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct MyObject
{
   [MarshalAs(UnmanagedType.LPWStr)]
   publ         


        
2条回答
  •  长情又很酷
    2021-02-06 15:57

    You probably mean:

    struct MyUnmanagedStruct {
        LPWSTR var1, var2;
    };
    

    Then you can use Marshal.StructureToPtras suggested by Botz3000. Otherwise C#'s

    public struct MyObject {
       public String var1;
       public String var2;
    }
    

    and C++/CLI's

    public struct value MyObject {
       public String^ var1;
       public String^ var2;
    }
    

    are completely equivalent, assuming your're you're using the same System.String on both sides.

提交回复
热议问题