pinvoke 中结构体的问题

gbf08711 2009-02-12 01:37:13
在c#工程中我需要Pinvoke一个c代码编写的函数a,假设其定义如下
void a(struct* b);
typedef struct
{
int x;
char b[10];
} c;
typedef struct
{
c aa[5];
char d[10];
}
在c#中需要怎么定义这两个结构体?




...全文
88 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pcjbird 2009-02-16
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lnpusky 的回复:]
C# code[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
public struct c {

/// int
public int x;

/// char[10]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=10)]
public string b;…
[/Quote]

这个貌似在.net cf 2.0中才能这样写~~~~~~~~~
pcjbird 2009-02-13
  • 打赏
  • 举报
回复
typedef struct
{
int x;
char b0;
char b1;
char b2;
char b3;
.
.
.
char b9;
} c;
typedef struct
{
c aa0;
.
.
.
c aa4;
char d0;
.
.
.
char d9;
}
SAP辉哥 2009-02-13
  • 打赏
  • 举报
回复
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
public struct c {

/// int
public int x;

/// char[10]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=10)]
public string b;
}

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet=System.Runtime.InteropServices.CharSet.Ansi)]
public struct Anonymous_5939246e_35c7_48ed_9aac_867f4088b5ca {

/// c[5]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst=5, ArraySubType=System.Runtime.InteropServices.UnmanagedType.Struct)]
public c[] aa;

/// char[10]
[System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=10)]
public string d;
}
儿大不由爷 2009-02-12
  • 打赏
  • 举报
回复
比较复杂呀,Google一下吧,网上有很多说明
儿大不由爷 2009-02-12
  • 打赏
  • 举报
回复
用类不行么?

7,656

社区成员

发帖
与我相关
我的任务
社区描述
Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区管理员
  • Windows客户端开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧