how to convert from LPCSTR to LPCWSTR in c++

后端 未结 2 1609
春和景丽
春和景丽 2020-12-20 16:54

additional info im building an application which use the WinHttpOpenRequest Api which requires LPCWSTR for the object name and im using visual studio 2008

2条回答
  •  攒了一身酷
    2020-12-20 17:18

    Converting from char * has a nice sample

    char *orig = "Hello, World!";
    cout << orig << " (char *)" << endl;
    
    // Convert to a wchar_t*
    size_t origsize = strlen(orig) + 1;
    const size_t newsize = 100;
    size_t convertedChars = 0;
    wchar_t wcstring[newsize];
    mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
    wcscat_s(wcstring, L" (wchar_t *)");
    wcout << wcstring << endl;
    

    But like tenfour mentioned. Use generic text mapping if possible

提交回复
热议问题