FacundoGFlores
FacundoGFlores

Reputation: 8118

Obtaining the windows desktop path

This is my code:

#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;
}

But myPath returns nothing. I just want to obtain the Desktop path. I'm on Windows 7 64 bits.

Upvotes: 1

Views: 843

Answers (1)

Joel Lucsy
Joel Lucsy

Reputation: 8706

You need to give it room to put the data into:

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

Upvotes: 5

Related Questions