Resolve Windows device path to drive letter
Hopefully the following piece of code will give you enough to solve this - after you've initialised it, you just need to iterate through the collection to find your match. You may want to convert everything to upper/lower case before you insert into the collection to help with lookup performance.
typedef basic_string<TCHAR> tstring;typedef map<tstring, tstring> HardDiskCollection;void Initialise( HardDiskCollection &_hardDiskCollection ){ TCHAR tszLinkName[MAX_PATH] = { 0 }; TCHAR tszDevName[MAX_PATH] = { 0 }; TCHAR tcDrive = 0; _tcscpy_s( tszLinkName, MAX_PATH, _T("a:") ); for ( tcDrive = _T('a'); tcDrive < _T('z'); ++tcDrive ) { tszLinkName[0] = tcDrive; if ( QueryDosDevice( tszLinkName, tszDevName, MAX_PATH ) ) { _hardDiskCollection.insert( pair<tstring, tstring>( tszLinkName, tszDevName ) ); } }}
Maybe you could use GetVolumeNameForMountPoint and iterate through all mount points A:\ through Z:\, breaking when you find a match?
http://msdn.microsoft.com/en-us/library/aa364994(VS.85).aspx
(I haven't tried this)
Following function does the job using C only
BOOL GetWin32FileName(const TCHAR* pszNativeFileName, TCHAR *pszWin32FileName){ BOOL bFound = FALSE; // Translate path with device name to drive letters. TCHAR szTemp[MAX_PATH]; szTemp[0] = '\0'; if (GetLogicalDriveStrings(MAX_PATH - 1, szTemp)) { TCHAR szName[MAX_PATH]; TCHAR szDrive[3] = TEXT(" :"); TCHAR* p = szTemp; do { // Copy the drive letter to the template string *szDrive = *p; // Look up each device name if (QueryDosDevice(szDrive, szName, MAX_PATH)) { size_t uNameLen = _tcslen(szName); if (uNameLen < MAX_PATH) { bFound = _tcsnicmp(pszNativeFileName, szName, uNameLen) == 0 && *(pszNativeFileName + uNameLen) == _T('\\'); if (bFound) { // Replace device path with DOS path StringCchPrintf(pszWin32FileName, MAX_PATH, TEXT("%s%s"), szDrive, pszNativeFileName + uNameLen); } } } // Go to the next NULL character. while (*p++); } while (!bFound && *p); } return(bFound);}