如何从LPCTSTR转换为字节数组 [英] How to convert from LPCTSTR to a Byte array
问题描述
大家好,
我必须使用现有的C ++ dll,其方法接受数组< byte>对于某些计算。
我有一个LPCTSTR,我使用Unicode,如何将这些字符串转换为字节数组?
如何将它们转换回LPCTSTR?
我尝试了几种方法但是,当它编译时,我得到的只是第一个字母,好像它没有考虑2个字节。
提前致谢,
Marco H.
< pre lang =css> 谢谢 你 for 您的 帮助。
此 < span class =code-leadattribute>问题:
int MyMethod(LPCTSTR inputA)
{
array < Byte> ^ MyStringArray = inputA ?????? // inputA的字节[]版本
..
LPCTSTR MyString = MyString ??? // MyStringArray转换后的字符串
..
}
Dll 不 Unicode 现在,可能 future ,取决于 < span class =code-leadattribute> customer 。
LPCTSTR 确定 < span class =code-leadattribute> for Ascii 和 Unicode , 转换 如果 inputA Ascii 或 Unicode?
WideCharToMultiByte 如果 Unicode? 如果 Ascii?
谢谢,
Marco H 。
正如 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 yourDLL
is notUNICODE
. Depending on your needs you have to perform a conversion (Have a look at "WideCharToMultiByte function"[^]).
这篇关于如何从LPCTSTR转换为字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!