开发者

File copying issue while converting to LPCTSTR

开发者 https://www.devze.com 2022-12-25 13:05 出处:网络
// Convert to a wchar_t* size_t origsize = strlen(toChar) + 1; 开发者_Python百科const size_t newsize = 100;
// Convert to a wchar_t*

size_t origsize = strlen(toChar) + 1;

开发者_Python百科const size_t newsize = 100;

size_t convertedChars = 0;

wchar_t wcstring[newsize];

mbstowcs_s(&convertedChars, wcstring, origsize, toChar, _TRUNCATE);

wcscat_s(wcstring, L"\\*.*\0");

wcout << wcstring << endl; // C:\Documents and Settings\softnotions\Desktop\Release\*.*



SHFILEOPSTRUCT sf;

memset(&sf,0,sizeof(sf));

sf.hwnd = 0;

sf.wFunc = FO_COPY;

//sf.pFrom =wcstring;  /* when giving wcstring i am not getting answer */

 sf.pFrom = L"C:\\Documents and Settings\\softnotions\\Desktop\\Release\\*.*\0";

   wcout << sf.pFrom  <<endl;   // C:\Documents and Settings\softnotions\Desktop\Release\*.*

Both wcstring and sf.pFrom are same then why not gettng answer when assigning sf.pFrom =wcstring;


SHFILEOPSTRUCT requires pFrom and pTo to be double-null-terminated strings.

The string literal you assign to pFrom has an embedded \0, so the string is double-null-terminated.

When you call wcscat_s, the embedded \0 is interpreted as the end of the string to append, so the resulting string is not double-null-terminated.

As you say in your comment, you can do this (although the function you need is wcslen):

wcscat_s(wcstring, L"\\*.*");
wcstring[wcslen(wcstring) + 1] = 0;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号