static QString p_getenv( QString name ) { DWORD len = QT_WA_INLINE( GetEnvironmentVariableW ( ( LPCWSTR ) qt_winTchar ( name, true ), NULL, 0 ), GetEnvironmentVariableA ( ( LPCSTR ) name.ascii(), NULL, 0 ) ); if ( len == 0 ) return QString::null; /* ansi: we allocate too much memory, but this shouldn't be the problem here ... */ LPTSTR buf = new WCHAR[ len ]; len = QT_WA_INLINE( GetEnvironmentVariableW ( ( LPCWSTR ) qt_winTchar ( name, true ), buf, len ), GetEnvironmentVariableA ( ( LPCSTR ) name.ascii(), ( char* ) buf, len ) ); if ( len == 0 ) return QString::null; QString ret = qt_winQString ( buf ); delete[] buf; return ret; }
/* * If we are on Windows, read application path from registry, key was set * during installation at HKEY_LOCAL_MACHINE\Software\qGo\Location */ QString Setting::getApplicationPath() { LONG res; HKEY hkey; QString s = NULL; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\qGo"), NULL, KEY_READ, &hkey) == ERROR_SUCCESS) { DWORD type = REG_SZ, size; char buffer[100]; size = sizeof(buffer); res = RegQueryValueEx(hkey, TEXT("Location"), NULL, &type, (PBYTE)&buffer, &size); RegCloseKey(hkey); s = qt_winQString(buffer); qDebug("getApplicationPath(): %s", s.latin1()); } return s; }