这个C++结构C#怎么写?

njxy 2003-01-15 04:54:23
原来有个DLL,是C++写的,里面有个函数test, 现在想用C#调用这个函数, 可是原参数是用结构写的,不知道C#中怎么写这个结构调用才对:
typedef struct struTest
{
char f1[11];
char f2[21];
char f3[11];
int num;
bool bexit;
}TstruTest;
bool test(TstruTest* stru);
...全文
18 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yarshray 2003-01-15
  • 打赏
  • 举报
回复
给篇文章你,应该对你这类1问题有帮助

http://www.microsoft.com/china/msdn/library/dncscol/html/csharp09192002.asp
njxy 2003-01-15
  • 打赏
  • 举报
回复
非常感谢各位,已经通过了!
njxy 2003-01-15
  • 打赏
  • 举报
回复
To: henryfan1(henry)
不行,您说的这个申明通不过。
现在我的问题是不知道如何申明这个结构,比如用
struct struTest
{
public string f1;
public string f2;
public string f3;
public int num;
public bool bexit;
}
最后会报找不到这个DLL的函数入口。
yarshray 2003-01-15
  • 打赏
  • 举报
回复
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct struTest
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
string f1;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 21)]
string f2;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 11)]
string f3;
int num;
bool bexit;
}TstruTest;

bool test(ref TstruTest stru);
chenbinghui 2003-01-15
  • 打赏
  • 举报
回复

[StructLayout(LayoutKind.Sequential)]
public struct TstruTest{
[MarshalAs(UnmanagedType.ByValArray,SizeConst:=11)]
public byte f1;
[MarshalAs(UnmanagedType.ByValArray,SizeConst:=21)]
public byte f2;
[MarshalAs(UnmanagedType.ByValArray,SizeConst:=11)]
public byte f3;
public int num;
public bool bexit;
}


[DllImport("your.dll")]
bool test([MarshalAs(UnmanagedType.Struct)] ref TstruTest stru);


henryfan1 2003-01-15
  • 打赏
  • 举报
回复
struct struTest
{
public char f1[];
public char f2[];
public char f3[];
public int num;
public bool bexit;
}
win32c 2003-01-15
  • 打赏
  • 举报
回复
[attributes] [modifiers] struct identifier [:interfaces] body [;]

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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