// find the type and size of the default value
DWORD type;
DWORD size; if ( RegQueryValueExW( hkey, nullptr, nullptr, &type, nullptr, &size ) != ERROR_SUCCESS ) return nullptr;
// get memory to hold the default value
std::unique_ptr<WCHAR[]> data(new WCHAR[size]);
// read the default value if ( RegQueryValueExW( hkey, nullptr, nullptr, &type, reinterpret_cast<LPBYTE>(data.get()), &size ) != ERROR_SUCCESS ) return nullptr;
return data.release();
}
/* Returns the path to the program folder of the brand layer, forexampleC:/ProgramFiles/LibreOffice/program ThispathiseitherobtainedfromtheenvironmentvariableUNO_PATH ortheregistryitem"Software\\LibreOffice\\UNO\\InstallPath" eitherinHKEY_CURRENT_USERorHKEY_LOCAL_MACHINE Thereturnvaluemustbefreedwithdelete[]
*/
WCHAR* getInstallPath()
{
std::unique_ptr<WCHAR[]> szInstallPath;
DWORD cChars = GetEnvironmentVariableW(UNO_PATH, nullptr, 0); if (cChars > 0)
{
szInstallPath.reset(new WCHAR[cChars]);
cChars = GetEnvironmentVariableW(UNO_PATH, szInstallPath.get(), cChars); // If PATH is not set then it is no error if (cChars == 0) return nullptr;
}
if (! szInstallPath)
{
szInstallPath.reset(getPathFromRegistryKey( HKEY_CURRENT_USER, INSTALL_PATH )); if (! szInstallPath)
{ // read the key's default value from HKEY_LOCAL_MACHINE
szInstallPath.reset(getPathFromRegistryKey( HKEY_LOCAL_MACHINE, INSTALL_PATH ));
}
} return szInstallPath.release();
}
/* We extend the path to contain the install folder, sothatcomponentscanuseosl_loadModulewitharguments,suchas "reg3.dll".Thatis,theargumentsareonlythelibrarynames.
*/ void extendPath(LPCWSTR szPath)
{ if (!szPath) return;
std::unique_ptr<WCHAR[]> sEnvPath;
DWORD cChars = GetEnvironmentVariableW(L"PATH", nullptr, 0); if (cChars > 0)
{
sEnvPath.reset(new WCHAR[cChars]);
cChars = GetEnvironmentVariableW(L"PATH", sEnvPath.get(), cChars); // If PATH is not set then it is no error if (cChars == 0 && GetLastError() != ERROR_ENVVAR_NOT_FOUND) return;
} // Prepare the new PATH. Add the directory at the front. // Note also adding ';'
std::unique_ptr<WCHAR[]> sNewPath(new WCHAR[lstrlenW(sEnvPath.get()) + lstrlenW(szPath) + 2]);
lstrcpyW(sNewPath.get(), szPath); if (lstrlenW(sEnvPath.get()))
{
lstrcatW(sNewPath.get(), L";");
lstrcatW(sNewPath.get(), sEnvPath.get());
}
SetEnvironmentVariableW(L"PATH", sNewPath.get());
}
HMODULE loadFromPath(LPCSTR sLibName)
{ if (!sLibName) return nullptr;
// Convert the ansi file name to wchar_t* int size = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sLibName, -1, nullptr, 0); if (size == 0) return nullptr;
std::unique_ptr<WCHAR[]> wsLibName(new WCHAR[size]); if (!MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sLibName, -1, wsLibName.get(), size)) return nullptr;
std::unique_ptr<WCHAR[]> szPath(getInstallPath()); if (!szPath) return nullptr;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.