22#include < string>
33#include < windows.h>
44
5- std::wstring GetNVDAPath ();
6- LONG GetStringRegKey (HKEY hKey, const std::wstring &strValueName, std::wstring &strValue, const std::wstring &strDefaultValue);
7-
85int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
96{
107 if (__argc < 2 ) {
@@ -24,51 +21,14 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpC
2421 cds.cbData = (args.length ()*2 )+2 ;
2522 HWND hwnd;
2623 hwnd = FindWindow (L" TeleNVDAURLHandler" , NULL );
27- if (hwnd == 0 ) {
28- NVDAPath = GetNVDAPath ();
29- ShellExecute (0 , NULL , NVDAPath.c_str (), NULL , NULL , 0 );
30- };
3124 for (int tries = 0 ; tries < 300 ; tries++) {
32- Sleep (100 );
33- hwnd = FindWindow (L" TeleNVDAURLHandler" , NULL );
34- if (hwnd > 0 ) {
25+ if (hwnd > (HWND)0 ) {
3526 Sleep (100 ); /* Needed to ensure the window is fully created */
3627 SendMessage (hwnd, WM_COPYDATA, 0 , (LPARAM)&cds);
3728 return 0 ;
3829 };
39- }
40- return 1 ;
41- }
42-
43- /* Get the path to the NVDA executable if installed
44- Return an empty string if the path cannot be found. */
45-
46- std::wstring GetNVDAPath () {
47- HKEY hKey;
48- LONG lRes = RegOpenKeyExW (HKEY_LOCAL_MACHINE, L" SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Uninstall\\ NVDA" , 0 , KEY_READ, &hKey);
49- if (lRes != ERROR_SUCCESS) {
50- return L" " ;
51- }
52- std::wstring result;
53- std::wstring BadValue;
54- GetStringRegKey (hKey, L" InstallDir" , result, L" bad" );
55- if (result == L" bad" ) {
56- return L" " ;
30+ Sleep (100 );
31+ hwnd = FindWindow (L" TeleNVDAURLHandler" , NULL );
5732 }
58- result += L" \\ NVDA.exe" ;
59- return result;
33+ return 1 ;
6034}
61-
62- LONG GetStringRegKey (HKEY hKey, const std::wstring &strValueName, std::wstring &strValue, const std::wstring &strDefaultValue)
63- {
64- strValue = strDefaultValue;
65- WCHAR szBuffer[512 ];
66- DWORD dwBufferSize = sizeof (szBuffer);
67- ULONG nError;
68- nError = RegQueryValueExW (hKey, strValueName.c_str (), 0 , NULL , (LPBYTE)szBuffer, &dwBufferSize);
69- if (ERROR_SUCCESS == nError)
70- {
71- strValue = szBuffer;
72- }
73- return nError;
74- }
0 commit comments