Anonymous
11/20/2007 11:35:00 PM
I'm trying to call a c++dll with an array of strings from vb.net. The c++dll
writes to these string buffers which are returned.
First I found out that the default marshaling in .net-fw doesn't copy back
the data written to the string buffers. Fixed that by adding the [in] and
[out] attributes.
But now I found out .net-fw throws an exception if the strings has byte
values >127, i.e. 8-bit ANSI instead of 7-bit ASCII. How can I fix
that? I wish to not use unicode in my c++dll. Is it possible to return an
array of 8-bit ANSI strings from a c++dll to vb.net?
' *** vb-code... ***
Private Declare Ansi Function GetFileProperties Lib "mycpp.dll" ( _
ByVal filename As String, _
ByVal array_size As Integer, _
ByVal element_size As Integer, _
<System.Runtime.InteropServices.[In](), _
System.Runtime.InteropServices.Out()> _
ByVal values() As String) As Integer
' Call c++ dll...
Dim array_size As Integer = 100
Dim element_size As Integer = 100
Dim values(array_size - 1) As String
For i As Integer = 0 To count - 1
values(i) = Space(valuesize - 1)
Next
Dim retval As Integer
retval = GetFileProperties(FileName, array_size, element_size, values)
// *** c++code... ***
int GetFileProperties(char *szFileName, int *array_size, int *element_size,
char **values)
{
strcpy(values[0], "testÅÄÖ");
return 0;
}