简体   繁体   中英

MultiByteToWideChar doesn't work properly

I'm trying to use MultiByteToWideChar api. for lpWideCharStr , when I use a pointer with dynamic memory allocation, it works properly. 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.

what's wrong with it?

how should I use a static memory allocated pointer for lpWideCharStr in MultiByteToWideChar ?

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};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM