Re: How to get local computer My Document FULL path?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sun, 22 Jun 2008 20:50:47 -0400
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?=" :Joseph M. Newcomer [MVP]
<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 **
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Prev by Date: Re: How to get local computer My Document FULL path?
- Next by Date: Re: unicode file
- Previous by thread: Re: How to get local computer My Document FULL path?
- Next by thread: Book recommendations
- Index(es):
Relevant Pages
|