Search code examples
c#c++stringlpcstrlptstr

Wrong value for LPCTSTR variable (?)


I have this method on a C++ project

long CPPProject::CPPMethod(long lValue, LPCTSTR Data){
    do something...
}

But, when I consume the method via a C# project, sometimes the value of Data is '?' For example:

C# code:

String sText1 = "u0110 \u0110"; //Đ
object.CPPMethod(lValue, sText1);

In this case, the 'Data' variable received the value correctly (Đ).

But on the other hand, if the code is:

C# code:

String sText2 = "u8162 \u8162";//腢 
object.CPPMethod(lValue, sText2);

The value of 'Data' is '?'

I write the value of Data on a log file.

Why is this behavior? What do I need to fix?


Solution

  • I replaced from LPCTSTR to LPCWSTR

    Basically is because; LPCWSTR is a const WCHAR *, and LPCTSTR const of TCHAR *, in addition in the DISP_FUNCTION, was a necessary change VTS_BSTR to VTS_WBSTR.

    After making this, the value was received without bugs