[英]MultiByteToWideChar doesn't work properly
I'm trying to use MultiByteToWideChar
api.我正在尝试使用MultiByteToWideChar
api。 for lpWideCharStr
, when I use a pointer with dynamic memory allocation, it works properly.对于lpWideCharStr
,当我使用具有动态内存分配的指针时,它可以正常工作。 but now I should use a pointer with static memory allocation as you see in the code.但是现在我应该使用一个带有静态内存分配的指针,正如您在代码中看到的那样。 and it doesn't work properly, return 0.并且它不能正常工作,返回 0。
what's wrong with it?它出什么问题了?
how should I use a static memory allocated pointer for lpWideCharStr
in MultiByteToWideChar
?我应该如何在MultiByteToWideChar
为lpWideCharStr
使用静态内存分配指针?
thank's for your solutions.感谢您的解决方案。
#include <windows.h>
#include <iostream>
#include "Shlwapi.h"
#pragma comment(lib,"shlwapi.lib")
void main(int argc, char *argv[]){
int iToSizeB = 0;
iToSizeB = MultiByteToWideChar(CP_UTF8, 0, argv[1], -1 , NULL, 0);
LPWSTR lpFileAddress[260] = {0};
int nResult = 0;
//MultiByteToWideChar function reurns 0 !!!
nResult = MultiByteToWideChar(CP_UTF8, 0, argv[1], -1, lpFileAddress[0], iToSizeB);
}
Probably you mean this:可能你的意思是:
WCHAR lpFileAddress[260] = {0};
nResult = MultiByteToWideChar(CP_UTF8, 0, argv[1], -1, lpFileAddress, iToSizeB);
In your code, you define array of WCHAR pointers: LPWSTR lpFileAddress[260]
instead of WCHAR
array, as required: WCHAR lpFileAddress[260] = {0};
在您的代码中,根据需要定义 WCHAR 指针数组: LPWSTR lpFileAddress[260]
而不是WCHAR
数组: WCHAR lpFileAddress[260] = {0};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.