Re: How to get local computer My Document FULL path?

Tech-Archive recommends: Speed Up your PC by fixing your registry



An overly-convoluted solution to a trivial problem. SHGetFolderPath does it all, with far
less effort.
joe

On Tue, 17 Jun 2008 02:35:53 -0400, "-Nivel-" <nomail@xxxxxxxx> wrote:

"=?Utf-8?B?TGFuZG9u?=" :
<news:D378F204-D5FA-43AF-8CE7-21197C45571C@xxxxxxxxxxxxx>
mar, 17 jun 2008 00:51:01 GMT

I use MFC Visual C++ 4.2. How to acquire full path of every computer
My Document folder? So when my application ran, it will directly
detect the new full path.

Thank you very much.


Maybe is this what you searching,

CString ClassX::GetMyDocumentsFolder()
{
#define BUFSIZE 1024
HKEY hKey;
TCHAR szDocFolder[BUFSIZE];
DWORD dwBufLen = BUFSIZE;
LONG lRet;

lRet = RegOpenKeyEx( HKEY_CURRENT_USER,
_T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\
User Shell Folders"),
0,
KEY_QUERY_VALUE,
&hKey );

if( lRet == ERROR_SUCCESS )
{
lRet = RegQueryValueEx( hKey,
_T("Personal"),
NULL,
NULL,
(LPBYTE) szDocFolder,
&dwBufLen);

if( (lRet == ERROR_SUCCESS) || (dwBufLen < BUFSIZE) )
{
RegCloseKey( hKey );

CString string(szDocFolder);

if( ExpandEnvStrings( string ) )
return string;
}
}

return CString();
}


BOOL ClassX::ExpandEnvStrings(CString &str)
{
LPTSTR lpszSystemInfo = 0; // pointer to system information string
TCHAR tchBuffer[BUFSIZE]; // buffer for string
DWORD dwResult = 0; // function return value

memset((void*)tchBuffer, 0, sizeof(tchBuffer)/sizeof(tchBuffer[0]));

lpszSystemInfo = tchBuffer;

dwResult = ExpandEnvironmentStrings( str, lpszSystemInfo, BUFSIZE);

CString s;

if( dwResult <= BUFSIZE )
{
s = lpszSystemInfo;
str = s;
return TRUE;
}

return FALSE;
}



// get MyDocuments Folder
CString dir = GetMyDocumentsFolder();



Nivel.


** Posted from http://www.teranews.com **
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: How to get local computer My Document FULL path?
    ... CString ClassX::GetMyDocumentsFolder ... HKEY hKey; ... DWORD dwBufLen = BUFSIZE; ... lRet = RegOpenKeyEx(HKEY_CURRENT_USER, ...
    (microsoft.public.vc.mfc)
  • Re: x64 Registry Reflection
    ... HKEY hKey; ... lRet = RegOpenKeyEx( ... printf("Ups...The Winlogon key cannot be opened..." ... ...compiles and runs fine in x86 and x64 environment but nothing seem ...
    (microsoft.public.win32.programmer.kernel)
  • Re: x64 Registry Reflection
    ... HKEY hKey; ... lRet = RegOpenKeyEx( ... printf("Ups...The Winlogon key cannot be opened..." ... Anybody got an idea how to get "Registry Reflection" working for the ...
    (microsoft.public.win32.programmer.kernel)
  • x64 Registry Reflection
    ... HKEY hKey; ... lRet = RegOpenKeyEx( ... printf("Ups...The Winlogon key cannot be opened..." ... ....compiles and runs fine in x86 and x64 environment but nothing seem ...
    (microsoft.public.win32.programmer.kernel)