How do I marshal a structure as a pointer to a structure?

前端 未结 3 504
自闭症患者
自闭症患者 2021-01-11 18:36

I am trying to pass a structure from C# into C++ library. I pass structure as an object, and C++ function expects it as a pointer (void *).

I am having problem pas

3条回答
  •  被撕碎了的回忆
    2021-01-11 19:29

    Try passing the structure as a ref parameter.

    [DllImport("MockVadavLib.dll", CharSet = CharSet.Ansi)]
    public static extern IntPtr TheFunction(ref UserRec userRec);
    

    When you use a ref combined with a structure, it conceptually passes the address.

提交回复
热议问题