RE: passing string array to C++

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi

Based on my research, all the System API on the WinCE is of Unicode
version, so it is common to handle all the string in the winCE of unicode
version.
I think it is better for you to convert your dll to handle Unicode version
string all the time.

Here is the WCHAR version P/Invoke for your reference.

[C++]
CPPDLL_API long MyAdapt( long g, WCHAR **strings, long numStrings)
{
for(int i=0;i<numStrings;i++)
{
printf("%S \n",strings[i]);
strings[i][2]='A'+i;
}
return 0;
}
extern "C" CPPDLL_API long MyAdapt( long g, WCHAR **strings, long
numStrings);


[C#]

[DllImport(@"..\..\..\CPPDLL\Debug\CPPDLL.dll",EntryPoint="MyAdapt",CharSet=
CharSet.Unicode,SetLastError=true)]
private static extern int MyAdapt(int g,[In,Out] string[] users, int
numUsers);
public static void InteropStringArray()
{
string[] strs = new string[]{"Hello","World"};
int rt = MyAdapt(2,strs,2);
foreach(string s in strs)
{
Console.WriteLine(s);
}
}
[STAThread]
static void Main(string[] args)
{
InteropStringArray();
}

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

.



Relevant Pages