将 char*[] 从 C++ DLL 结构体传递到 C#
passing char*[] from c++ dll Struct to c#
我正在尝试通过c ++ DLL将以下结构传递给c#:
struct name
{ char* myArray[3];
char firstname[100];
char lastname[100];
};
void Caller(struct name * demo)
{
strcpy(demo->firstname,"hello");
demo->myArray[0]="hello";
demo->myArray[1]="hello";
demo->myArray[2]="hello";
ping(demo); //call to c# function
}
下面是我的 c# 代码:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct name
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string firstname;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string lastname;
//what should i marshal here for char* myArray[3];
} ;
static void Main(string[] args)
{
name myname = new name();
ping( ref myname);
}
public static void ping(int a,ref name myname)
{
Console.WriteLine(myname.firstname+"n");
}
我能够从c ++ dll导入名字和姓氏。
我应该怎么做才能从 c++ 导入字符指针数组?
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct Name
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string FirstName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 100)]
public string LastName;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public string[] Array;
};
对于我的完整解决方案,请检查 Foo.cpp 和程序.cs:https://gist.github.com/3779066
相关文章:
- 根据用户回答声明"Players"。用户选择玩家数量。播放器是结构体
- 结构体 S { int align; } 之间的区别;(struct 关键字后的名称)和 struct { int al
- C++ - 如何在结构向量中找到结构体一个成员的最大值?
- 包含 std::list 的结构体的 C++ 初始化
- 结构体和类的不同大小(),彼此具有相同的字段类型
- 如何使用结构体的向量数组?
- 如何使用结构体在C++中更改这些代码?
- 无法在 Mosquitto MQTT Broker 插件上访问结构体 mosquitto 的元素
- 我应该如何在C++中使用结构体解决输入失败的问题?
- Qsort() 比较结构体整数的总和
- 如何使用迭代器指向结构体c++的向量
- 将 char*[] 从 C++ DLL 结构体传递到 C#
- 如何从D DLL返回C结构体
- 调用返回结构体的c++ DLL函数
- 如何从c++ dll中导入结构体?
- 如何将c++结构体传递给c# DLL
- 从c++ dll中获取结构体到c#应用程序中
- 在ce5上从c#传递结构体并在非托管c++ dll中修改的问题
- 从c#程序到c++ win32 DLL共享结构体的最佳实践
- 从c#发送带有动态字符串数组的结构体到c++ dll