how can i pass char* or string to byte*[] in C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

sorry i am poor in English.
i am trying to call functions from a "dll"(maybe developed in C++), there is
a struct in this function,which is defined like this:
typedef struct{
..........
BYTE * BS[5];
..........
}DBDIS;
this struct is used as parameter in some functions,and in fact every element
in this array is char*,it's a pointer to the first character in a string.
my problem:how can i pass char* or string to this array in C#
thanks.
 
???? said:
sorry i am poor in English.
i am trying to call functions from a "dll"(maybe developed in C++), there
is
a struct in this function,which is defined like this:
typedef struct{
..........
BYTE * BS[5];
..........
}DBDIS;
this struct is used as parameter in some functions,and in fact every
element
in this array is char*,it's a pointer to the first character in a string.
my problem:how can i pass char* or string to this array in C#
thanks.

I think you need to marshall it as an array of char:


[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
struct DBDIS
{
[MarshalAs(UnmanagedType.LPArray, SizeConst=5)]
char[] BS;
}

David
 
it doesn't work,David.
each element in BS(DLL struct) is a pointer to a null terminated string(C++),
although it's a byte*[].
how can i convert this C++ struct to a C# struct.
thanks David.

David Browne said:
???? said:
sorry i am poor in English.
i am trying to call functions from a "dll"(maybe developed in C++), there
is
a struct in this function,which is defined like this:
typedef struct{
..........
BYTE * BS[5];
..........
}DBDIS;
this struct is used as parameter in some functions,and in fact every
element
in this array is char*,it's a pointer to the first character in a string.
my problem:how can i pass char* or string to this array in C#
thanks.

I think you need to marshall it as an array of char:


[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
struct DBDIS
{
[MarshalAs(UnmanagedType.LPArray, SizeConst=5)]
char[] BS;
}

David
 
Back
Top