Solved

how get path to MyDocuments folder

Posted on 2014-03-14
5
328 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 285 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now