C++代码:
struct a
{
int x;
b y[10];
c z[10];//b,c都是下面定义的结构体
}struct b
{
int aa;
int bb;
}struct c
{
float cc;
double dd;
}导出函数:
int GetInfo(a* pINFO)C#里面该怎么定义结构体a,并调用函数GetInfo,读取pInfo地址里的值?烦恼了一天,也没找出好的解决办法,请大家帮帮忙,谢谢
struct a
{
int x;
b y[10];
c z[10];//b,c都是下面定义的结构体
}struct b
{
int aa;
int bb;
}struct c
{
float cc;
double dd;
}导出函数:
int GetInfo(a* pINFO)C#里面该怎么定义结构体a,并调用函数GetInfo,读取pInfo地址里的值?烦恼了一天,也没找出好的解决办法,请大家帮帮忙,谢谢
这样行不?
或是看看
属性。具体的这个要测试才能知道对不对。只给你个方向。懒得弄vc项目测试了。
相应参数(结构体)需要自己重新定义
char[] 对应 string
int 对应 int32
long 对应int64
指针 对应 intptr
。。导入C函数
[Dllimport("你的dll.dll")]
public static extern int GetInfo(ref yourStruct info);结构体定义
[StructLayout(LayoutKind.Sequential)]
struct yourStruct
{
//成员定义。要跟C中对应
}
[StructLayout(LayoutKind.Sequential)]
struct a
{
int x;
b y[10];
c z[10];//b,c都是下面定义的结构体
}[StructLayout(LayoutKind.Sequential)]
struct b
{
int aa;
int bb;
}[StructLayout(LayoutKind.Sequential)]
struct c
{
float cc;
double dd;
}
struct a
{
int x;
b[] y;
c[] z;//b,c都是下面定义的结构体
}
这里面的y和z都是数组,不用特殊说明吗?
我记得连int数组都要向下面这样定义
[MarshalAs(UnmanagedType.ByValArray, sizeConst = 6)]
public int[] test;