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