c++ - InvalidArgs 尝试在 C++ 中使用 UrlCreateFromPath 时

标签 c++ visual-c++

我正在尝试使用 C++ 中的 UrlCreateFromPath() 函数将文件路径转换为 ​​fileUrl。

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

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);

关于c++ - InvalidArgs 尝试在 C++ 中使用 UrlCreateFromPath 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33972646/

相关文章:

调整速度值时 C++ 矩形未正确定位?

c++ - 使用自动构建系统进行版本控制

c++ - Eigen :使用 SparseMatrix 的 selfAdjointView

c++进程启动路径问题

c++ - 输出流运算符的重载

c++ - 使用 boost 工厂在构造函数中传递参数

c++ - 将有符号和无符号十六进制转换为 dec 和 dec 为十六进制 C++

c++ - 为什么 sprintf_s 在不同版本的 Visual Studio 中给出不同的结果?

python - 与python26链接的visual studio中的编译错误

c++ - Double 已经在 main.obj 中定义