visual InvalidArgs当尝试在c++中使用UrlCreateFromPath时

visual InvalidArgs When trying to use UrlCreateFromPath in c++

本文关键字:UrlCreateFromPath c++ InvalidArgs visual      更新时间:2023-10-16

我正在尝试使用c++中的UrlCreateFromPath()函数将filepath转换为fileUrl。

以下代码尝试将文件路径转换为文件URL

PCTSTR lpszUnicode = L"C:\Users\TBD\Downloads\index.html";
PTSTR output =L"C:\Users\TBD\Downloads\index.html";
DWORD dwDisp = 0;
DWORD dw2 = 0;
LPDWORD lpdwDisp = &dwDisp;
HRESULT res2 = UrlCreateFromPath(lpszUnicode, output, lpdwDisp, dw2);
std::wstring newOutput(output);

但res2总是显示InvalidArgs。我在上面的代码快照中做错了什么吗?

实际写入常量缓冲区(维奇错误)

PCTSTR lpszUnicode = L"C:\Users\TBD\Downloads\index.html";
//PTSTR output =L"C:\Users\TBD\Downloads\index.html"; cannot do that way
TCHAR output[MAX_PATH]; // allocate buffer in memory (stack)
DWORD dwDisp = MAX_PATH; // max posible buffer size
LPDWORD lpdwDisp = &dwDisp;
HRESULT res2 = UrlCreateFromPath(lpszUnicode, output, lpdwDisp, NULL);
std::wstring newOutput(output);

你为什么要做

LPDWORD lpdwDisp = &dwDisp;

你可以简单地这样做

HRESULT res2 = UrlCreateFromPath(lpszUnicode, output, &dwDisp, dw2);
相关文章:
  • 没有找到相关文章