Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how get path to MyDocuments folder

Posted on 2014-03-14
5
Medium Priority
?
336 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

715 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