August 8, 200916 yr Commercial Member As Bill so kindly provided a quick'n'easy way to find out which version of FS is installed, I thought I'd throw in a minor extension of his subroutine which gets the installation path based on the executable.//**************************************************************************//Get simulator version//**************************************************************************int simVer=-1;void GetSimVer(){ WIN32_FIND_DATA ffd; // file information struct HANDLE sh; char searchPath[MAX_PATH];// no need for a directory qualifier because all DLL's run within// the simulator's main folder since they run as children of the main simulator executable. strncpy(searchPath,"fsx.exe\0",8); sh=FindFirstFile(searchPath,&ffd); if(sh==INVALID_HANDLE_VALUE) { strncpy(searchPath,"fs9.exe\0",8); sh=FindFirstFile(searchPath,&ffd); if(sh==INVALID_HANDLE_VALUE)simVer=-1; else simVer=9; } else simVer=10; return;}//**************************************************************************//Get simulator path - must be preceeded by GetSimVer()//**************************************************************************char simPath[256]="";void getSimPath(){ HKEY hkey; DWORD dwKeytype; DWORD dwLenPath=200; if(simVer==9) { RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Microsoft Games\\Flight Simulator\\9.0",0,KEY_QUERY_VALUE,&hkey ); RegQueryValueEx(hkey,"EXE Path",NULL,&dwKeytype,(BYTE*)&simPath,&dwLenPath); RegCloseKey(hkey); } else if(simVer==10) { RegOpenKeyEx(HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Microsoft Games\\Flight Simulator\\10.0",0,KEY_QUERY_VALUE,&hkey ); RegQueryValueEx(hkey,"SetupPath",NULL,&dwKeytype,(BYTE*)&simPath,&dwLenPath); RegCloseKey(hkey); } return;}-Dai
August 9, 200916 yr Moderator Cool beans! :) Fr. Bill AOPA Member: 07141481 AARP Member: 3209010556 Avsim Board of Directors | Avsim Forums Moderator
August 10, 200916 yr You're leaking a handle, the one returned from FindFirstFile :->Tim Tim http://fsandm.wordpress.com
Create an account or sign in to comment