如何从LPCTSTR转换为字节数组 [英] How to convert from LPCTSTR to a Byte array

查看:91
本文介绍了如何从LPCTSTR转换为字节数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我必须使用现有的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 your DLL is not UNICODE. Depending on your needs you have to perform a conversion (Have a look at "WideCharToMultiByte function"[^]).


这篇关于如何从LPCTSTR转换为字节数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆