/** * Our very own SHGetFolderPath function for support of windows operating * systems that don't have this function (eg Win9x, etc.). We try using the * native function, and if that doesn't exist we will try a more crude approach * of environment variables and hope for the best */ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) { static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL; static bool first_time = true; /* We only try to load the library one time; if it fails, it fails */ if (first_time) { #if defined(UNICODE) # define W(x) x "W" #else # define W(x) x "A" #endif /* The function lives in shell32.dll for all current Windows versions, but it first started to appear in SHFolder.dll. */ if (!LoadLibraryList((Function*)&SHGetFolderPath, "shell32.dll\0" W("SHGetFolderPath") "\0\0")) { if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) { DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from either shell32.dll or SHFolder.dll"); } } #undef W first_time = false; } if (SHGetFolderPath != NULL) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath); /* SHGetFolderPath doesn't exist, try a more conservative approach, * eg environment variables. This is only included for legacy modes * MSDN says: that 'pszPath' is a "Pointer to a null-terminated string of * length MAX_PATH which will receive the path" so let's assume that * Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0, * Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0, * Windows NT 4.0 with Service Pack 4 (SP4) */ { DWORD ret; switch (csidl) { case CSIDL_FONTS: // Get the system font path, eg %WINDIR%\Fonts ret = GetEnvironmentVariable(_T("WINDIR"), pszPath, MAX_PATH); if (ret == 0) break; _tcsncat(pszPath, _T("\\Fonts"), MAX_PATH); return (HRESULT)0; case CSIDL_PERSONAL: case CSIDL_COMMON_DOCUMENTS: { HKEY key; if (RegOpenKeyEx(csidl == CSIDL_PERSONAL ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, REGSTR_PATH_SPECIAL_FOLDERS, 0, KEY_READ, &key) != ERROR_SUCCESS) break; DWORD len = MAX_PATH; ret = RegQueryValueEx(key, csidl == CSIDL_PERSONAL ? _T("Personal") : _T("Common Documents"), NULL, NULL, (LPBYTE)pszPath, &len); RegCloseKey(key); if (ret == ERROR_SUCCESS) return (HRESULT)0; break; } /* XXX - other types to go here when needed... */ } } return E_INVALIDARG; }
/** * Our very own SHGetFolderPath function for support of windows operating * systems that don't have this function (eg Win9x, etc.). We try using the * native function, and if that doesn't exist we will try a more crude approach * of environment variables and hope for the best */ HRESULT OTTDSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPTSTR pszPath) { static HRESULT (WINAPI *SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR) = NULL; static bool first_time = true; /* We only try to load the library one time; if it fails, it fails */ if (first_time) { #if defined(UNICODE) # define W(x) x "W" #else # define W(x) x "A" #endif if (!LoadLibraryList((Function*)&SHGetFolderPath, "SHFolder.dll\0" W("SHGetFolderPath") "\0\0")) { DEBUG(misc, 0, "Unable to load " W("SHGetFolderPath") "from SHFolder.dll"); } #undef W first_time = false; } if (SHGetFolderPath != NULL) return SHGetFolderPath(hwnd, csidl, hToken, dwFlags, pszPath); /* SHGetFolderPath doesn't exist, try a more conservative approach, * eg environment variables. This is only included for legacy modes * MSDN says: that 'pszPath' is a "Pointer to a null-terminated string of * length MAX_PATH which will receive the path" so let's assume that * Windows 95 with Internet Explorer 5.0, Windows 98 with Internet Explorer 5.0, * Windows 98 Second Edition (SE), Windows NT 4.0 with Internet Explorer 5.0, * Windows NT 4.0 with Service Pack 4 (SP4) */ { DWORD ret; switch (csidl) { case CSIDL_FONTS: // Get the system font path, eg %WINDIR%\Fonts ret = GetEnvironmentVariable(_T("WINDIR"), pszPath, MAX_PATH); if (ret == 0) break; _tcsncat(pszPath, _T("\\Fonts"), MAX_PATH); return (HRESULT)0; /* XXX - other types to go here when needed... */ } } return E_INVALIDARG; }
const char *MusicDriver_DMusic::Start(const char * const *parm) { if (performance != NULL) return NULL; if (proc.CoCreateInstance == NULL) { if (!LoadLibraryList((Function*)&proc, ole_files)) { return "ole32.dll load failed"; } } /* Initialize COM */ if (FAILED(proc.CoInitialize(NULL))) { return "COM initialization failed"; } /* create the performance object */ if (FAILED(proc.CoCreateInstance( CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC, IID_IDirectMusicPerformance, (LPVOID*)&performance ))) { proc.CoUninitialize(); return "Failed to create the performance object"; } /* initialize it */ if (FAILED(performance->Init(NULL, NULL, NULL))) { performance->Release(); performance = NULL; proc.CoUninitialize(); return "Failed to initialize performance object"; } /* choose default Windows synth */ if (FAILED(performance->AddPort(NULL))) { performance->CloseDown(); performance->Release(); performance = NULL; proc.CoUninitialize(); return "AddPort failed"; } /* create the loader object; this will be used to load the MIDI file */ if (FAILED(proc.CoCreateInstance( CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC, IID_IDirectMusicLoader, (LPVOID*)&loader ))) { performance->CloseDown(); performance->Release(); performance = NULL; proc.CoUninitialize(); return "Failed to create loader object"; } return NULL; }