marshalling : C# string to C++ CString

  • Thread starter Thread starter Romain TAILLANDIER
  • Start date Start date
R

Romain TAILLANDIER

Hi group

I have a C++ dll containing the following functions :

extern APIENTRY WINAPI void F1(CString str1,CString str2)
{
F2(str1,str2);
}

/*intern*/ void F2(CString str1,CString str2)
{
//do stuffs ..;
}

I have this C# code :

[DllImport("my.dll", EntryPoint = "F1")]
public static extern bool csFct(string s1 ,string s2);

When i call to csFct passing two string in parameter, I get the call of F1
correctly in the DLL, but it bug when calling F2.
I suppose it is due to marshalling poblems, but i am newbie to that, so
please help :)

how can i convert internally my strings to CStrings inside the F1 fonction,
where they are allready CStrings... ?
it is confusing for me.

thank you for help.
ROM
 
When i call to csFct passing two string in parameter, I get the call of F1
correctly in the DLL, but it bug when calling F2.

The problem is in the call to F1, but you may not see it result in
failure until you call F2. The solution is to replace the F1 parameter
types with one of the native string types the runtime knows about
(LPSTR, LPWSTR or BSTR), and then handle the conversion to CString
internally in the C++ code.



Mattias
 
Back
Top