gpt4 book ai didi

c++ - 转换为 LPCTSTR 时出现文件复制问题

转载 作者:行者123 更新时间:2023-11-28 08:30:05 24 4
gpt4 key购买 nike

// Convert to a wchar_t*

size_t origsize = strlen(toChar) + 1;

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\*.*

wcstringsf.pFrom 是一样的,那么为什么在分配 sf.pFrom =wcstring; 时不得到答案

最佳答案

SHFILEOPSTRUCT 要求 pFrompTodouble-null-terminated strings .

您分配给 pFrom 的字符串文字具有嵌入的 \0,因此该字符串以双 null 结尾。

当您调用 wcscat_s 时,嵌入的 \0 被解释为要追加的字符串的末尾,因此生成的字符串不是双空终止的。

正如您在评论中所说,您可以这样做(尽管您需要的功能是wcslen):

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

关于c++ - 转换为 LPCTSTR 时出现文件复制问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2537831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com