Solved

how get path to MyDocuments folder

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
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.

634 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