Skip to content

Commit ad54195

Browse files
committed
Use different logic to get registry key.
1 parent b702f8c commit ad54195

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ warned, it can easily take several hours, but at least it's automatic)::
388388
389389
vcpkg install mpir:x64-windows glibmm:x64-windows (go have a coffee)
390390
vcpkg install sqlite3:x64-windows boost:x64-windows (go for dinner)
391-
vcpkg install gtkmm:x64-windows winreg:x64-windows (run overnight)
391+
vcpkg install gtkmm:x64-windows (run overnight)
392392
vcpkg integrate install
393393

394394
boost-system:x64-windows

client_server/cadabra-server.cc

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,33 @@
66

77
#ifdef _WIN32
88
#include <Windows.h>
9-
#include <WinReg.hpp>
9+
#endif
10+
11+
#ifdef _WIN32
12+
13+
std::string getRegKey(const std::string& location, const std::string& name)
14+
{
15+
HKEY key;
16+
TCHAR value[1024];
17+
DWORD bufLen = 1024*sizeof(TCHAR);
18+
long ret;
19+
ret = RegOpenKeyExA(HKEY_CURRENT_USER, location.c_str(), 0, KEY_QUERY_VALUE, &key);
20+
if( ret != ERROR_SUCCESS ){
21+
return std::string();
22+
}
23+
ret = RegQueryValueExA(key, name.c_str(), 0, 0, (LPBYTE) value, &bufLen);
24+
RegCloseKey(key);
25+
if ( (ret != ERROR_SUCCESS) || (bufLen > 1024*sizeof(TCHAR)) ){
26+
return std::string();
27+
}
28+
std::string stringValue = std::string(value, (size_t)bufLen - 1);
29+
size_t i = stringValue.length();
30+
while( i > 0 && stringValue[i-1] == '\0' ){
31+
--i;
32+
}
33+
return stringValue.substr(0,i);
34+
}
35+
1036
#endif
1137

1238
// Run a simple Cadabra server on a local port.
@@ -19,9 +45,8 @@ int main()
1945
// by querying a registry key.
2046
std::string pythonhome=Glib::getenv("PYTHONHOME");
2147
std::string pythonpath=Glib::getenv("PYTHONPATH");
22-
23-
winreg::RegKey key{ winreg::HKEY_CURRENT_USER, L"SOFTWARE\\Python\\PythonCore\\3.7" };
24-
std::wstring s = key.GetStringValue(L"");
48+
49+
std::string s = getRegKey("SOFTWARE\\Python\\PythonCore\\3.7", "");
2550

2651
// Glib::setenv("PYTHONHOME", (pythonhome.size()>0)?(pythonhome+":"):"" + Glib::get_home_dir()+"/Anaconda3");
2752
// Glib::setenv("PYTHONPATH", (pythonpath.size()>0)?(pythonpath+":"):"" + Glib::get_home_dir()+"/Anaconda3");

0 commit comments

Comments
 (0)