Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how get path to MyDocuments folder

Posted on 2014-03-14
5
Medium Priority
?
337 Views
Last Modified: 2014-03-14
hi
need to know how get path to MyDocuments folder using C++ ?  I'm not looking for syntax of VS but some thing that can be used in all IDE. I'll create binary file and will save it after creation in MyDocuments folder.
0
Comment
Question by:mastiSoft
  • 3
  • 2
5 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39929569
You could try the following:
CHAR folder_path[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, folder_path);

Open in new window

Remembering to include Windows.h and ShlObj.h.
0
 
LVL 1

Author Comment

by:mastiSoft
ID: 39929583
This is what I get
 error: C2664: 'SHGetFolderPathW' : cannot convert parameter 5 from 'CHAR [260]' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
0
 
LVL 1

Author Comment

by:mastiSoft
ID: 39929588
#include <iostream>
#include <Windows.h>
#include <shlobj.h>
using namespace std;


#pragma comment(lib, "shell32.lib")

int main()
{
CHAR folder_path[MAX_PATH];
HRESULT result = SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, folder_path);


    return 0;
}

Open in new window

Why this not works?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 1140 total points
ID: 39929653
Try like this instead:
#include <iostream>
#include <Windows.h>
#include <shlobj.h>
using namespace std;


#pragma comment(lib, "shell32.lib")

int main()
{
CHAR folder_path[MAX_PATH];
HRESULT result = SHGetFolderPathA(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, folder_path);

return 0;
}

Open in new window

0
 
LVL 1

Author Closing Comment

by:mastiSoft
ID: 39929743
Thank you now it works and return path. the only difference I can see is SHGetFolderPathA.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question