1

这是我的代码:

#include <Windows.h>
#include <ShlObj.h>
#include <iostream>

using namespace std;

int main()
{
    LPTSTR myPath = NULL;

    SHGetSpecialFolderPath(0, myPath, CSIDL_COMMON_DESKTOPDIRECTORY, FALSE);

    if(myPath != NULL)
        cout << "It returns something" << endl;
    else
        cout << "It returns nothing" << endl;
    system("PAUSE");
    return 0;
}

但 myPath 什么也不返回。我只想获取桌面路径。我在 Windows 7 64 位。

4

1 回答 1

5

您需要给它空间将数据放入:

T_CHAR myPath[ MAX_PATH ];
SHGetSpecialFolderPath(0, myPath, CSIDL_COMMON_DESKTOPDIRECTORY, FALSE);
于 2012-12-10T22:24:58.763 回答