We do not need to retain the hInstance value passed into WinMain(), as
it's always available as GetModuleHandle(NULL).
Note that DialogBox() accepts NULL meaning "the current executable" in
any case.
Future work: there's still some completely unnecessary storing it in
class Window and passing it around.
---
dialog.h | 3 ---
gui/SitePage.cc | 3 +--
install.cc | 2 +-
main.cc | 5 +----
msg.cc | 5 ++---
netio.cc | 10 +++++-----
6 files changed, 10 insertions(+), 18 deletions(-)
diff --git a/dialog.h b/dialog.h
index 63c98ee..ebbf661 100644
--- a/dialog.h
+++ b/dialog.h
@@ -20,9 +20,6 @@
#include "win32.h"
-/* global instance for the application; set in main.cc */
-extern HINSTANCE hinstance;
-
/* used by main.cc to select the next do_* function */
extern int next_dialog;
diff --git a/gui/SitePage.cc b/gui/SitePage.cc
index 1cdb1bf..9dacebc 100644
--- a/gui/SitePage.cc
+++ b/gui/SitePage.cc
@@ -367,8 +367,7 @@ int check_dropped_mirrors (HWND h)
{
if (unattended_mode)
return CACHE_ACCEPT_WARN;
- return DialogBox (hinstance, MAKEINTRESOURCE (IDD_DROPPED), h,
- drop_proc);
+ return DialogBox (NULL, MAKEINTRESOURCE (IDD_DROPPED), h, drop_proc);
}
return CACHE_ACCEPT_NOWARN;
}
diff --git a/install.cc b/install.cc
index 628dbd0..001529b 100644
--- a/install.cc
+++ b/install.cc
@@ -660,7 +660,7 @@ Installer::_installOne (packagemeta &pkgm,
dlg_data.processlist = plm.c_str ();
dlg_data.iteration = iteration;
- rc = DialogBoxParam(hinstance, MAKEINTRESOURCE
(IDD_FILE_INUSE), owner, FileInuseDlgProc, (LPARAM)&dlg_data);
+ rc = DialogBoxParam(NULL, MAKEINTRESOURCE
(IDD_FILE_INUSE), owner, FileInuseDlgProc, (LPARAM)&dlg_data);
}
else
{
diff --git a/main.cc b/main.cc
index 4c391f5..8a68232 100644
--- a/main.cc
+++ b/main.cc
@@ -86,8 +86,6 @@ extern char **_argv;
bool is_new_install = false;
std::string SetupIniDir;
-HINSTANCE hinstance;
-
static StringChoiceOption::StringChoices symlink_types({
{"native", SymlinkTypeNative},
{"lnk", SymlinkTypeShortcut},
@@ -176,7 +174,7 @@ main_display ()
}
// Init window class lib
- Window::SetAppInstance (hinstance);
+ Window::SetAppInstance (GetModuleHandle(NULL));
// Create pages
Splash.Create ();
@@ -221,7 +219,6 @@ int WINAPI
WinMain (HINSTANCE h,
HINSTANCE hPrevInstance, LPSTR command_line, int cmd_show)
{
- hinstance = h;
// Make sure Windows DLLs only delay-load further DLLs from System32
typedef BOOL (WINAPI *PFNSETDEFAULTDLLDIRECTORIES)(DWORD);
diff --git a/msg.cc b/msg.cc
index 8e344ff..b53df86 100644
--- a/msg.cc
+++ b/msg.cc
@@ -23,7 +23,6 @@
#include <stdio.h>
#include <stdarg.h>
-#include "dialog.h"
#include "state.h"
#include "String++.h"
#include "resource.h"
@@ -66,7 +65,7 @@ mbox (HWND owner, const char *buf, const char *name, int type)
}
char caption[32];
- LoadString (hinstance, IDS_MBOX_CAPTION, caption, sizeof (caption));
+ LoadString (GetModuleHandle(NULL), IDS_MBOX_CAPTION, caption, sizeof
(caption));
return MessageBox (owner, buf, caption, type);
}
@@ -76,7 +75,7 @@ mbox (HWND owner, const char *name, int type, int id, va_list
args)
{
char buf[1000], fmt[1000];
- if (LoadString (hinstance, id, fmt, sizeof (fmt)) <= 0)
+ if (LoadString (GetModuleHandle(NULL), id, fmt, sizeof (fmt)) <= 0)
ExitProcess (0);
vsnprintf (buf, 1000, fmt, args);
diff --git a/netio.cc b/netio.cc
index 631532a..d6bfc24 100644
--- a/netio.cc
+++ b/netio.cc
@@ -185,9 +185,9 @@ auth_proc (HWND h, UINT message, WPARAM wParam, LPARAM
lParam)
}
static int
-auth_common (HINSTANCE h, int id, HWND owner)
+auth_common (int id, HWND owner)
{
- return DialogBox (h, MAKEINTRESOURCE (id), owner, auth_proc);
+ return DialogBox (NULL, MAKEINTRESOURCE (id), owner, auth_proc);
}
int
@@ -195,7 +195,7 @@ NetIO::get_auth (HWND owner)
{
user = &net_user;
passwd = &net_passwd;
- return auth_common (hinstance, IDD_NET_AUTH, owner);
+ return auth_common (IDD_NET_AUTH, owner);
}
int
@@ -203,7 +203,7 @@ NetIO::get_proxy_auth (HWND owner)
{
user = &net_proxy_user;
passwd = &net_proxy_passwd;
- return auth_common (hinstance, IDD_PROXY_AUTH, owner);
+ return auth_common (IDD_PROXY_AUTH, owner);
}
int
@@ -221,7 +221,7 @@ NetIO::get_ftp_auth (HWND owner)
}
user = &net_ftp_user;
passwd = &net_ftp_passwd;
- return auth_common (hinstance, IDD_FTP_AUTH, owner);
+ return auth_common (IDD_FTP_AUTH, owner);
}
const char *
--
2.43.0