社区
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 怎么获取地址
...全文
637
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#
COM 参数是
结构体
数组
在
C#
中,
结构体
数组是使用数组类型来定义的,如 `_CAPI_Point3d[] tst = new _CAPI_Point3d[count];`。在这个例子中,我们定义了一个 _CAPI_Point3d
结构体
数组,数组长度为 count。 Marshal 类 在
C#
中,...
C++
结构体
/函数定义转换
C#
函数定义/
结构体
本文将深入探讨如何将C++的
结构体
、数据类型和函数定义转换为
C#
,并结合提供的文件列表,讨论可能涉及的工具和技术。 首先,C++和
C#
虽然都是面向对象的编程语言,但在语法和类型系统上有显著差异。C++支持模板、...
C#
调用C++
封装
成DLL的
结构体
及类库.rar
本主题聚焦于如何在
C#
中调用由C++
封装
成的DLL(动态链接库),涉及到了
结构体
、类库以及如何处理输入输出参数,如`out`和`ref`。下面我们将深入探讨这些知识点。 1. **
C#
调用C++ DLL**:这是.NET框架提供的一种特性...
C#
111,131
社区成员
642,542
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章