/***************************************************************************** * DRIVER_GetDriverName * */ BOOL DRIVER_GetDriverName( LPCWSTR device, LPWSTR driver, DWORD size ) { static const WCHAR displayW[] = { 'd','i','s','p','l','a','y',0 }; static const WCHAR devicesW[] = { 'd','e','v','i','c','e','s',0 }; static const WCHAR display1W[] = {'\\','\\','.','\\','D','I','S','P','L','A','Y','1',0}; static const WCHAR empty_strW[] = { 0 }; WCHAR *p; /* display is a special case */ if (!strcmpiW( device, displayW ) || !strcmpiW( device, display1W )) { lstrcpynW( driver, displayW, size ); return TRUE; } size = GetProfileStringW(devicesW, device, empty_strW, driver, size); if(!size) { WARN("Unable to find %s in [devices] section of win.ini\n", debugstr_w(device)); return FALSE; } p = strchrW(driver, ','); if(!p) { WARN("%s entry in [devices] section of win.ini is malformed.\n", debugstr_w(device)); return FALSE; } *p = 0; TRACE("Found %s for %s\n", debugstr_w(driver), debugstr_w(device)); return TRUE; }
static HMMIO get_mmioFromProfile(UINT uFlags, LPCWSTR lpszName) { WCHAR str[128]; LPWSTR ptr; HMMIO hmmio; HKEY hRegSnd, hRegApp, hScheme, hSnd; DWORD err, type, count; static const WCHAR wszSounds[] = {'S','o','u','n','d','s',0}; static const WCHAR wszDefault[] = {'D','e','f','a','u','l','t',0}; static const WCHAR wszKey[] = {'A','p','p','E','v','e','n','t','s','\\', 'S','c','h','e','m','e','s','\\', 'A','p','p','s',0}; static const WCHAR wszDotDefault[] = {'.','D','e','f','a','u','l','t',0}; static const WCHAR wszDotCurrent[] = {'.','C','u','r','r','e','n','t',0}; static const WCHAR wszNull[] = {0}; TRACE("searching in SystemSound list for %s\n", debugstr_w(lpszName)); GetProfileStringW(wszSounds, lpszName, wszNull, str, sizeof(str)/sizeof(str[0])); if (lstrlenW(str) == 0) { if (uFlags & SND_NODEFAULT) goto next; GetProfileStringW(wszSounds, wszDefault, wszNull, str, sizeof(str)/sizeof(str[0])); if (lstrlenW(str) == 0) goto next; } for (ptr = str; *ptr && *ptr != ','; ptr++); if (*ptr) *ptr = 0; hmmio = mmioOpenW(str, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); if (hmmio != 0) return hmmio; next: /* we look up the registry under * HKCU\AppEvents\Schemes\Apps\.Default * HKCU\AppEvents\Schemes\Apps\<AppName> */ if (RegOpenKeyW(HKEY_CURRENT_USER, wszKey, &hRegSnd) != 0) goto none; if (uFlags & SND_APPLICATION) { DWORD len; err = 1; /* error */ len = GetModuleFileNameW(0, str, sizeof(str)/sizeof(str[0])); if (len > 0 && len < sizeof(str)/sizeof(str[0])) { for (ptr = str + lstrlenW(str) - 1; ptr >= str; ptr--) { if (*ptr == '.') *ptr = 0; if (*ptr == '\\') { err = RegOpenKeyW(hRegSnd, ptr+1, &hRegApp); break; } } } } else { err = RegOpenKeyW(hRegSnd, wszDotDefault, &hRegApp); } RegCloseKey(hRegSnd); if (err != 0) goto none; err = RegOpenKeyW(hRegApp, lpszName, &hScheme); RegCloseKey(hRegApp); if (err != 0) goto none; /* what's the difference between .Current and .Default ? */ err = RegOpenKeyW(hScheme, wszDotDefault, &hSnd); if (err != 0) { err = RegOpenKeyW(hScheme, wszDotCurrent, &hSnd); RegCloseKey(hScheme); if (err != 0) goto none; } count = sizeof(str)/sizeof(str[0]); err = RegQueryValueExW(hSnd, NULL, 0, &type, (LPBYTE)str, &count); RegCloseKey(hSnd); if (err != 0 || !*str) goto none; hmmio = mmioOpenW(str, NULL, MMIO_ALLOCBUF | MMIO_READ | MMIO_DENYWRITE); if (hmmio) return hmmio; none: WARN("can't find SystemSound=%s !\n", debugstr_w(lpszName)); return 0; }
wchar_t * UT_GetDefaultPrinterName() { UT_uint32 iBufferSize = 128; // will become 2x bigger immediately in the loop wchar_t * pPrinterName = NULL; DWORD rc; do { iBufferSize *= 2; if(pPrinterName) g_free(pPrinterName); pPrinterName = (wchar_t *) UT_calloc(sizeof(wchar_t),iBufferSize); UT_return_val_if_fail( pPrinterName, NULL ); // the method of obtaining the name is version specific ... OSVERSIONINFOW osvi; DWORD iNeeded, iReturned, iBuffSize; LPPRINTER_INFO_5W pPrinterInfo; wchar_t* p; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); GetVersionExW(&osvi); if (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { // get size of the buffer needed to call enum printers if (!EnumPrintersW(PRINTER_ENUM_DEFAULT,NULL,5,NULL,0,&iNeeded,&iReturned)) { if ((rc = GetLastError()) != ERROR_INSUFFICIENT_BUFFER) { return NULL; } } // allocate the buffer if ((pPrinterInfo = (LPPRINTER_INFO_5W)LocalAlloc(LPTR,iNeeded)) == NULL) { rc = GetLastError(); } else { // now get the default printer if (!EnumPrintersW(PRINTER_ENUM_DEFAULT,NULL,5, (LPBYTE) pPrinterInfo,iNeeded,&iNeeded,&iReturned)) { rc = GetLastError(); } else { if (iReturned > 0) { // here we copy the name to our own buffer if ((DWORD) wcslen(pPrinterInfo->pPrinterName) > iBufferSize-1) { rc = ERROR_INSUFFICIENT_BUFFER; } else { wcscpy(pPrinterName,pPrinterInfo->pPrinterName); rc = ERROR_SUCCESS; } } else { *pPrinterName = '0'; rc = ERROR_SUCCESS; } } LocalFree(pPrinterInfo); } } else if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) { if (osvi.dwMajorVersion >= 5) /* Windows 2000 or later */ { iBuffSize = iBufferSize; HMODULE hWinSpool = LoadLibraryW(L"winspool.drv"); if (!hWinSpool) return NULL; HRESULT (WINAPI * fnGetDefaultPrinter)(LPWSTR, LPDWORD) = (HRESULT (WINAPI * )(LPWSTR, LPDWORD)) GetProcAddress(hWinSpool, GETDEFAULTPRINTER); if (!fnGetDefaultPrinter) { FreeLibrary(hWinSpool); return NULL; } bool i =false; if (!fnGetDefaultPrinter(pPrinterName,&iBuffSize)) i = true; if(i) rc = GetLastError(); else rc = ERROR_SUCCESS; FreeLibrary(hWinSpool); } else /* Windows NT 4.0 or earlier */ { if (GetProfileStringW(L"windows",L"device",L"",pPrinterName,iBufferSize) == iBufferSize-1) { rc = ERROR_INSUFFICIENT_BUFFER; } else { p = pPrinterName; while (*p != '0' && *p !=L',') ++p; *p = '0'; rc = ERROR_SUCCESS; } } } } while (rc == ERROR_INSUFFICIENT_BUFFER); return pPrinterName; }