s*****w 发帖数: 215 | 1 最近在写一个C#调用C++ 的dll的东西
遇到这样一个struct
struct A
{
unsigned int numConnections;
char** connectionName;
char** connectionDesc;
}
请问在C#里面的对应的struct怎么写呢 |
s*****w 发帖数: 215 | 2 或者比较弱的问一下C++中
这里为什么用char**
这和string有什么区别?
【在 s*****w 的大作中提到】 : 最近在写一个C#调用C++ 的dll的东西 : 遇到这样一个struct : struct A : { : unsigned int numConnections; : char** connectionName; : char** connectionDesc; : } : 请问在C#里面的对应的struct怎么写呢
|
t****t 发帖数: 6806 | 3 you should ask the original author why he used char**.
usually string is declared as char*, or const char*.
you can consider char** as pointer to string, whether that makes sense to
you is beyond my knowledge. but pointer to string is a completely different
creature from string.
【在 s*****w 的大作中提到】 : 或者比较弱的问一下C++中 : 这里为什么用char** : 这和string有什么区别?
|
d****n 发帖数: 1637 | 4 let me try to answer you this.
This would be like, in your example, a struct manage multiple "Connections."
Struct A a;
a.numberConnections=1;
a.ConnectionsName[0]="CName1"; //mem allocation and str copy ommited
a.ConnecttionDesc[0]="first Connections";
When you have more than one connections.
then ;
a.numberConnections++;
a.Connectionsnames[a.numberConnections-1] ="secondName";
a.ConnectionDesc[a.numberConnections-1]="Second Description here";
So char ** here is for maintain multiple c-string.
You treat it as a 2-D string.
but , be careful memory allocations in each string is different size(depends
on the size of each string.)
how it works in C#, I dont know. anyone?
【在 s*****w 的大作中提到】 : 或者比较弱的问一下C++中 : 这里为什么用char** : 这和string有什么区别?
|
o****e 发帖数: 916 | 5 here is an example:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
struct MyStruct
{
public static readonly int SizeOf = Marshal.SizeOf(typeof(MyStruct));
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr,
SizeConst = 256)]
public string name;
[MarshalAs(System.Runtime.InteropServices.UnmanagedType.I4)]
public int value;
} |
N********n 发帖数: 8363 | 6
Make sure no C++ exceptions ever get thrown into the C# runtime, or
your app could mysteriously crash. One problem of mixed-mode apps.
【在 s*****w 的大作中提到】 : 最近在写一个C#调用C++ 的dll的东西 : 遇到这样一个struct : struct A : { : unsigned int numConnections; : char** connectionName; : char** connectionDesc; : } : 请问在C#里面的对应的struct怎么写呢
|
t*****n 发帖数: 4908 | 7 char**是指向char*指针。
【在 s*****w 的大作中提到】 : 或者比较弱的问一下C++中 : 这里为什么用char** : 这和string有什么区别?
|