解决这个问题需要走两步,第一是将CString转换为const char*类型,第二部是将const char*转换为wchar_t*类型。
代码如下:
CString imagepath;
int count = 0;
count++;
imagePath.Format(_T("E:\\image%d"), count);
imagePath += ".bmp";
string str;
str = CStringA(imagePath);
const char* str2;
str2 = str.c_str();
//以上是将CString转换为const char*
size_t len = strlen(str2) + 1;
size_t converted = 0;
wchar_t *WStr;
WStr = (wchar_t*)malloc(len*sizeof(wchar_t));
mbstowcs_s(&converted, WStr, len, str2, _TRUNCATE);
ImageFileParams.pwchFileName = WStr;