Solved

how get path to MyDocuments folder

Posted on 2014-03-14
5
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 125
How to print into std::string like sprintf using C++11? 12 182
Error C2678: binary '!=': no operator found... 4 73
How do i run a c++ file? 15 58
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…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
This video teaches viewers about errors in exception handling.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

734 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