社区
C#
帖子详情
C# 怎么封装含有指针的结构体
youqingyike
2014-08-18 01:22:12
结构体里面含有 char*,int*,char[],int[],
比如:C 或C++ 动态库中,函数接口参数如下,
全是输入参数,
typedef struct MyStruct
{
char* pChar;
int* pInt;
char arrChar[20];
int arrInt[10];
}
C# 中如何封装对应结构体,求指教,主要是char* pChar 和 int* pInt 怎么获取地址
...全文
506
5
打赏
收藏
C# 怎么封装含有指针的结构体
结构体里面含有 char*,int*,char[],int[], 比如:C 或C++ 动态库中,函数接口参数如下, 全是输入参数, typedef struct MyStruct { char* pChar; int* pInt; char arrChar[20]; int arrInt[10]; } C# 中如何封装对应结构体,求指教,主要是char* pChar 和 int* pInt 怎么获取地址
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
youqingyike
2014-08-18
打赏
举报
回复
C的Dll 结构体定义如下: typedef struct structPointer { void* pvVoid; bool* pBool; char* pChar; int* pInt; short* pShort; long* lpLong; unsigned char* pucChar; unsigned int* puiInt; unsigned short* pusShort; unsigned long* pulLong; float* pFloat; double* pDouble; }stPointer,*pstPointer; C# 中对应结构体定义如下: [StructLayout(LayoutKind.Sequential)] public struct stPointer { [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pvVoid; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pBool; public string pChar; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pInt; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pShort; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr lpLong; public string pucChar; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr puiInt; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pusShort; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pulLong; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pFloat; [MarshalAs(UnmanagedType.SysUInt)] public IntPtr pDouble; }; C中函数 : _declspec(dllexport) void pointStruct(stPointer stTest); C#中对应定义: [DllImport("DataTypeTest_Dll.dll", EntryPoint = "pointStruct")] public static extern void pointStruct(stPointer stTest); 调用后,地址传值是正确,除字符串 public string pChar; 和 public string pucChar; 正确, 其他值都不对,有的是非常大的负值,不知什么原因
youqingyike
2014-08-18
打赏
举报
回复
谢谢,我看下
相思梦
2014-08-18
打赏
举报
回复
typedef struct MyStruct { char* pChar; int* pInt; char arrChar[20]; int arrInt[10]; } [StructLayout(LayoutKind.Sequential)] public unsafe struct MyStruct{ public char* pChar; char* pChar; int* pInt; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] string arrChar; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)] int[] arrInt; }
宝_爸
2014-08-18
打赏
举报
回复
string和int[]吧。 看看这篇讨论:
http://stackoverflow.com/questions/11968960/how-use-pinvoke-for-c-struct-array-pointer-to-c-sharp
bdmh
2014-08-18
打赏
举报
回复
http://blog.csdn.net/sdl2005lyx/article/details/6801113
C#
结构体
指针
的定义及使用详解
C#
结构体
指针
的定义及使用详解
调用示例.rar_
C#
调用c++ dll_
C#
调用函数
指针
_
C#
调用
结构体
_
结构体
_调用C dll
C#
调用C++ dll, 包括
结构体
, 数组, 函数
指针
, 字符串等等
基于
C#
调用c++Dll
结构体
数组
指针
的问题详解
下面小编就为大家分享一篇基于
C#
调用c++Dll
结构体
数组
指针
的问题详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
关于
结构体
指针
类型的强制转换
在学习stm32嵌入式开发过程中,关于对GPIOA等地址的强制性
结构体
指针
类型转换的参考依据!
C#
调用C++生成的DLL,并返回
结构体
引用或者
结构体
指针
多个值
C#
调用C++生成的DLL,并返回
结构体
引用或者
结构体
指针
多个值,工程已编译好
C#
110,567
社区成员
642,567
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章