Alexander Shargin (rudankort@softspb.com), May 31, 2002.
There is a number of "standard" folders on Pocket PC (such as \Windows, \Program Files etc.). The problem is, many of these folders are named differently on localized Pocket PCs. So it's not recommended to hard-code their names in your program. Instead you should determine the name of standard folder "on the fly". This article describes how to do this.
SHGetSpecialFolderPath function (and its counterpart SHGetSpecialFolderLocation) is designed specially to obtain full path to a special folder. This function is used like this.
TCHAR szStartupFolderPath[MAX_PATH]; ::SHGetSpecialFolderPath(NULL, szStartupFolderPath, CSIDL_STARTUP, FALSE);
CSIDL_STARTUP is a language-independent special folder identifier. Full list of supported folder identifiers can be found in documentation article on SHGetSpecialFolderLocation. Alas, there are no identifiers for \Windows, \Program files, \My documents and some other important folders. If you need to get path to one of these folders you will have to use other ways.
According to some newsgroup posts from MS people this folder is always named the same. You can also use this code to determine location of \Windows folder:
TCHAR buf[MAX_PATH];
GetModuleFileName(::GetModuleHandle(_T("coredll.dll")), buf, MAX_PATH);
*_tcsrchr(buf, _T('\\')) = _T('\0');
Although it is not documented the name of \Program Files folder (without leading backslash) can be found in this registry value: HKEY_LOCAL_MACHINE\PMail\Attachments\TopDir. You can get this value from registry like this:
#include <atlbase.h>
...
CRegKey regKey;
regKey.Open(HKEY_LOCAL_MACHINE, _T("PMail\\Attachments"));
TCHAR szProgramFilesFolderPath[MAX_PATH];
DWORD dwCount;
regKey.QueryValue(szProgramFilesFolderPath, _T("TopDir"), &dwCount);
regKey.Close();
This folder is also named the same on all devices so you can hard-code it into your programs. If you are using MFC you can also load the string from resources:
CString strMyDocFolderPath((LPCTSTR)AFXCE_IDS_INTL_DIRMYDOCUMENTS); // Now strMyDocFolderPath contains path to 'My documents' folder.