繁体   English   中英

将IntPtr转换为c#结构指针

[英]converting IntPtr as c# struct pointer

我有一个非托管的C ++函数,其内容类似于: int myfunction(LPVOID p1, LPVOID p2)

我在C#中的包装器将extern static int mywrapperFunction(IntPtr p1, IntPtr p2)

在我的包装函数定义中,我想将IntPtr引用到结构上。

在C ++中:

int myfunction(LPVOID p1, LPVOID p2)
{
    (MYFIRSTSTRUCTURE *)abc = (MYFIRSTSTRUCTURE *)p1;
    (MYSECONDSTRUCTURE *)efg = (MYSECONDSTRUCTURE *)p1;
    //rest of the operation involves this abc and efg
}

我需要在C#中做类似的事情:

int mywrapperFunction(IntPtr p1, IntPtr p2)
{
   //how to consume IntPtr p1 and IntPtr p2 for C# structure similar to MYFIRSTSTRUCTURE and //MYSECONDSTRUCTURE
}

处理此问题的正常方法是通过Marshal.PtrToStructure

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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