0

I am trying to get the local Appdata folder, and store it in a string. I seem to be doing something wrong with my variables though, since I am getting an access violation when I try to store the folderpath into a string.

Code:

PSTR buffer;
HRESULT hRes = SHGetSpecialFolderPathA(NULL, buffer, CSIDL_APPDATA, FALSE);
std::string executingPathFolder = buffer;
1
  • buffer point to what ? Commented May 27, 2018 at 9:27

1 Answer 1

0

Let's look at MSDN

lpszPath [out]

A pointer to a null-terminated string that receives the drive and path of the specified folder. This buffer must be at least MAX_PATH characters in size.

You must be careful with WinAPI - some methods returning buffers allocates them, some like write to allocated buffer. Please look here how to constructy std::string from LPSTR How do I convert from LPCTSTR to std::string?

Sign up to request clarification or add additional context in comments.

2 Comments

A pointer to a null-terminated string .. - this is wrong. lpszPath must point to buffer at least MAX_PATH characters in size. but initial context of the buffer does not matter.
I have tried to use those solutions, but they dont work, i am still getting an access violaten

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.