Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/144.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 获取windows桌面路径_C++_Windows_Winapi - Fatal编程技术网

C++ 获取windows桌面路径

C++ 获取windows桌面路径,c++,windows,winapi,C++,Windows,Winapi,这是我的代码: #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)

这是我的代码:

#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;
}
#包括
#包括
#包括
使用名称空间std;
int main()
{
LPTSTR myPath=NULL;
SHGetSpecialFolderPath(0,myPath,CSIDL\u COMMON\u DESKTOPDIRECTORY,FALSE);
if(myPath!=NULL)

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

T_CHAR myPath[ MAX_PATH ];
SHGetSpecialFolderPath(0, myPath, CSIDL_COMMON_DESKTOPDIRECTORY, FALSE);

您需要给it留出空间将数据放入:

T_CHAR myPath[ MAX_PATH ];
SHGetSpecialFolderPath(0, myPath, CSIDL_COMMON_DESKTOPDIRECTORY, FALSE);

谢谢。我不使用windows api,所以这是我第一次使用。t_CHAR和LPTSTR之间有什么区别?LPTSTR无法从系统调用接收输出?谢谢!LPTSTR是一个指针,在代码中它不指向任何东西。您需要向函数传递一个缓冲区(内存块)它可以存储字符串。
LPTSTR
是指向
TCHAR
的指针。你应该使用
TCHAR
而不是
T\u CHAR
。啊,对不起,没有键入TCHAR。谢谢。我不使用windows api,所以这是我第一次使用。T\u CHAR和LPTSTR之间有什么区别?LPTSTR无法接收来自s的输出系统调用?谢谢!LPTSTR是一个指针,在您的代码中它不指向任何东西。您需要向函数传递一个缓冲区(一块内存),它可以存储字符串。
LPTSTR
是指向
TCHAR
的指针。您应该使用
TCHAR
而不是
T\u CHAR
。啊,对不起,键入的TCHAR。