Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,
I have to use an existing C++ dll with methods that accept a array<byte> for some calculations.
I have an LPCTSTR and I am using Unicode, how can I convert those strings into byte arrays?
How to convert them back to LPCTSTR?

I tried in a few ways but, when it does compile, all I get is the first letter as if it was not considering the 2 bytes.

Thanks in advance,
Marco H.


CSS
Thanks you for your help.
This is the problem:

int MyMethod(LPCTSTR inputA)
{
    array<Byte>^ MyStringArray = inputA?????? // Byte[] version from inputA
    ..
    LPCTSTR MyString = MyString???// converted string from MyStringArray
    ..
}

Dll is not Unicode now, probably in future, depends on the customer.
LPCTSTR is OK for Ascii and Unicode, how to convert if inputA is Ascii or Unicode?

WideCharToMultiByte if Unicode? if Ascii?

Thanks,

Marco H.
Posted
Updated 11-Aug-15 8:51am
v2
Comments
Pascal-78 11-Aug-15 11:13am    
What did you try?
It's look like the C++ DLL is not unicode and LPCTSTR is same as LPCSTR (i.e. TCHAR is not wchar_t but char).

1 solution

As already noted by Pascal-78, probably your DLL is not UNICODE. Depending on your needs you have to perform a conversion (Have a look at "WideCharToMultiByte function"[^]).
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900