且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从LPCTSTR转换为字节数组

更新时间:2022-10-22 16:18:08

正如 Pascal-78 所述>,可能你的 DLL 不是 UNICODE 。根据您的需要,您必须执行转换(请查看WideCharToMultiByte功能 [ ^ ])。


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.


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.

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"[^]).