From 0170d6b9957bca15070ddf570476a3d5c6a9b80a Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Tue, 25 Aug 2015 16:39:50 +0300 Subject: [PATCH 1/8] Fixed GetModuleHandle to be universal. --- src/osd/modules/debugger/win/debugviewinfo.c | 12 +++++++----- src/osd/modules/debugger/win/debugwininfo.c | 6 ++++-- src/osd/modules/debugger/win/editwininfo.c | 4 +++- src/osd/windows/input.c | 10 ++++++---- src/osd/windows/output.c | 6 ++++-- src/osd/windows/window.c | 6 ++++-- src/osd/windows/winmain.c | 2 +- src/osd/windows/winutil.c | 14 +++++++++++++- src/osd/windows/winutil.h | 1 + 9 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/osd/modules/debugger/win/debugviewinfo.c b/src/osd/modules/debugger/win/debugviewinfo.c index b4868800692..504c90f2bf1 100644 --- a/src/osd/modules/debugger/win/debugviewinfo.c +++ b/src/osd/modules/debugger/win/debugviewinfo.c @@ -15,6 +15,8 @@ #include "strconv.h" +#include "winutil.h" + // debugger view styles #define DEBUG_VIEW_STYLE WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN @@ -48,15 +50,15 @@ debugview_info::debugview_info(debugger_windows_interface &debugger, debugwin_in // create the child view m_wnd = CreateWindowEx(DEBUG_VIEW_STYLE_EX, TEXT("MAMEDebugView"), NULL, DEBUG_VIEW_STYLE, - 0, 0, 100, 100, parent, NULL, GetModuleHandle(NULL), this); + 0, 0, 100, 100, parent, NULL, GetModuleHandleUni(), this); if (m_wnd == NULL) goto cleanup; // create the scroll bars m_hscroll = CreateWindowEx(HSCROLL_STYLE_EX, TEXT("SCROLLBAR"), NULL, HSCROLL_STYLE, - 0, 0, 100, CW_USEDEFAULT, m_wnd, NULL, GetModuleHandle(NULL), this); + 0, 0, 100, CW_USEDEFAULT, m_wnd, NULL, GetModuleHandleUni(), this); m_vscroll = CreateWindowEx(VSCROLL_STYLE_EX, TEXT("SCROLLBAR"), NULL, VSCROLL_STYLE, - 0, 0, CW_USEDEFAULT, 100, m_wnd, NULL, GetModuleHandle(NULL), this); + 0, 0, CW_USEDEFAULT, 100, m_wnd, NULL, GetModuleHandleUni(), this); if ((m_hscroll == NULL) || (m_vscroll == NULL)) goto cleanup; @@ -254,7 +256,7 @@ HWND debugview_info::create_source_combobox(HWND parent, LONG_PTR userdata) { // create a combo box HWND const result = CreateWindowEx(COMBO_BOX_STYLE_EX, TEXT("COMBOBOX"), NULL, COMBO_BOX_STYLE, - 0, 0, 100, 1000, parent, NULL, GetModuleHandle(NULL), NULL); + 0, 0, 100, 1000, parent, NULL, GetModuleHandleUni(), NULL); SetWindowLongPtr(result, GWLP_USERDATA, userdata); SendMessage(result, WM_SETFONT, (WPARAM)metrics().debug_font(), (LPARAM)FALSE); @@ -789,7 +791,7 @@ void debugview_info::register_window_class() // initialize the description of the window class wc.lpszClassName = TEXT("MAMEDebugView"); - wc.hInstance = GetModuleHandle(NULL); + wc.hInstance = GetModuleHandleUni(); wc.lpfnWndProc = &debugview_info::static_view_proc; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(2)); diff --git a/src/osd/modules/debugger/win/debugwininfo.c b/src/osd/modules/debugger/win/debugwininfo.c index 1a3258c1cab..fd6c4fdb099 100644 --- a/src/osd/modules/debugger/win/debugwininfo.c +++ b/src/osd/modules/debugger/win/debugwininfo.c @@ -17,6 +17,8 @@ #include "window.h" #include "winutf8.h" +#include "winutil.h" + bool debugwin_info::s_window_class_registered = false; @@ -36,7 +38,7 @@ debugwin_info::debugwin_info(debugger_windows_interface &debugger, bool is_main_ register_window_class(); m_wnd = win_create_window_ex_utf8(DEBUG_WINDOW_STYLE_EX, "MAMEDebugWindow", title, DEBUG_WINDOW_STYLE, - 0, 0, 100, 100, win_window_list->m_hwnd, create_standard_menubar(), GetModuleHandle(NULL), this); + 0, 0, 100, 100, win_window_list->m_hwnd, create_standard_menubar(), GetModuleHandleUni(), this); if (m_wnd == NULL) return; @@ -580,7 +582,7 @@ void debugwin_info::register_window_class() // initialize the description of the window class wc.lpszClassName = TEXT("MAMEDebugWindow"); - wc.hInstance = GetModuleHandle(NULL); + wc.hInstance = GetModuleHandleUni(); wc.lpfnWndProc = &debugwin_info::static_window_proc; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(2)); diff --git a/src/osd/modules/debugger/win/editwininfo.c b/src/osd/modules/debugger/win/editwininfo.c index 1ccd96ff7aa..279bc68fbe3 100644 --- a/src/osd/modules/debugger/win/editwininfo.c +++ b/src/osd/modules/debugger/win/editwininfo.c @@ -13,6 +13,8 @@ #include "strconv.h" +#include "winutil.h" + // edit box styles #define EDIT_BOX_STYLE WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL @@ -32,7 +34,7 @@ editwin_info::editwin_info(debugger_windows_interface &debugger, bool is_main_co // create an edit box and override its key handling m_editwnd = CreateWindowEx(EDIT_BOX_STYLE_EX, TEXT("EDIT"), NULL, EDIT_BOX_STYLE, - 0, 0, 100, 100, window(), NULL, GetModuleHandle(NULL), NULL); + 0, 0, 100, 100, window(), NULL, GetModuleHandleUni(), NULL); m_original_editproc = (WNDPROC)(FPTR)GetWindowLongPtr(m_editwnd, GWLP_WNDPROC); SetWindowLongPtr(m_editwnd, GWLP_USERDATA, (LONG_PTR)this); SetWindowLongPtr(m_editwnd, GWLP_WNDPROC, (LONG_PTR)&editwin_info::static_edit_proc); diff --git a/src/osd/windows/input.c b/src/osd/windows/input.c index ec08277bcf4..ef2f3108900 100644 --- a/src/osd/windows/input.c +++ b/src/osd/windows/input.c @@ -38,6 +38,8 @@ #include "strconv.h" #include "config.h" +#include "winutil.h" + //============================================================ // PARAMETERS //============================================================ @@ -1117,7 +1119,7 @@ static void dinput_init(running_machine &machine) int didevtype_joystick = DI8DEVCLASS_GAMECTRL; dinput_version = DIRECTINPUT_VERSION; - result = DirectInput8Create(GetModuleHandle(NULL), dinput_version, IID_IDirectInput8, (void **)&dinput, NULL); + result = DirectInput8Create(GetModuleHandleUni(), dinput_version, IID_IDirectInput8, (void **)&dinput, NULL); if (result != DI_OK) { dinput_version = 0; @@ -1130,17 +1132,17 @@ static void dinput_init(running_machine &machine) // first attempt to initialize DirectInput at the current version dinput_version = DIRECTINPUT_VERSION; - result = DirectInputCreate(GetModuleHandle(NULL), dinput_version, &dinput, NULL); + result = DirectInputCreate(GetModuleHandleUni(), dinput_version, &dinput, NULL); if (result != DI_OK) { // if that fails, try version 5 dinput_version = 0x0500; - result = DirectInputCreate(GetModuleHandle(NULL), dinput_version, &dinput, NULL); + result = DirectInputCreate(GetModuleHandleUni(), dinput_version, &dinput, NULL); if (result != DI_OK) { // if that fails, try version 3 dinput_version = 0x0300; - result = DirectInputCreate(GetModuleHandle(NULL), dinput_version, &dinput, NULL); + result = DirectInputCreate(GetModuleHandleUni(), dinput_version, &dinput, NULL); if (result != DI_OK) { dinput_version = 0; diff --git a/src/osd/windows/output.c b/src/osd/windows/output.c index 142488c3c15..ae6ea535334 100644 --- a/src/osd/windows/output.c +++ b/src/osd/windows/output.c @@ -17,6 +17,8 @@ // MAMEOS headers #include "output.h" +#include "winutil.h" + //============================================================ @@ -101,7 +103,7 @@ bool windows_osd_interface::output_init() 1, 1, NULL, NULL, - GetModuleHandle(NULL), + GetModuleHandleUni(), NULL); assert(output_hwnd != NULL); @@ -167,7 +169,7 @@ static int create_window_class(void) // initialize the description of the window class wc.lpszClassName = OUTPUT_WINDOW_CLASS; - wc.hInstance = GetModuleHandle(NULL); + wc.hInstance = GetModuleHandleUni(); wc.lpfnWndProc = output_window_proc; // register the class; fail if we can't diff --git a/src/osd/windows/window.c b/src/osd/windows/window.c index 1bb225f3e0b..a16a39286b8 100644 --- a/src/osd/windows/window.c +++ b/src/osd/windows/window.c @@ -35,6 +35,8 @@ #include "config.h" #include "winutf8.h" +#include "winutil.h" + extern int drawnone_init(running_machine &machine, osd_draw_callbacks *callbacks); extern int drawgdi_init(running_machine &machine, osd_draw_callbacks *callbacks); extern int drawdd_init(running_machine &machine, osd_draw_callbacks *callbacks); @@ -885,7 +887,7 @@ static void create_window_class(void) // initialize the description of the window class wc.lpszClassName = TEXT("MAME"); - wc.hInstance = GetModuleHandle(NULL); + wc.hInstance = GetModuleHandleUni(); wc.lpfnWndProc = winwindow_video_window_proc_ui; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(2)); @@ -1191,7 +1193,7 @@ int win_window_info::complete_create() monitorbounds.left() + 100, monitorbounds.top() + 100, NULL,//(win_window_list != NULL) ? win_window_list->m_hwnd : NULL, menu, - GetModuleHandle(NULL), + GetModuleHandleUni(), NULL); if (m_hwnd == NULL) return 1; diff --git a/src/osd/windows/winmain.c b/src/osd/windows/winmain.c index 54afff74298..74317eb30aa 100644 --- a/src/osd/windows/winmain.c +++ b/src/osd/windows/winmain.c @@ -1321,7 +1321,7 @@ FPTR symbol_manager::get_text_section_base() dynamic_bind image_nt_header(TEXT("dbghelp.dll"), "ImageNtHeader"); // start with the image base - PVOID base = reinterpret_cast(GetModuleHandle(NULL)); + PVOID base = reinterpret_cast(GetModuleHandleUni()); assert(base != NULL); // make sure we have the functions we need diff --git a/src/osd/windows/winutil.c b/src/osd/windows/winutil.c index adc78c36c75..c778f0b604b 100644 --- a/src/osd/windows/winutil.c +++ b/src/osd/windows/winutil.c @@ -92,7 +92,7 @@ BOOL win_is_gui_application(void) is_first_time = FALSE; // get the current module - module = GetModuleHandle(NULL); + module = GetModuleHandleUni(); if (!module) return FALSE; image_ptr = (BYTE*) module; @@ -122,3 +122,15 @@ BOOL win_is_gui_application(void) } return is_gui_frontend; } + +//------------------------------------------------- +// Universal way to get module handle +//------------------------------------------------- + +HMODULE WINAPI GetModuleHandleUni() +{ + MEMORY_BASIC_INFORMATION mbi; + static int dummy; + VirtualQuery(&dummy, &mbi, sizeof(mbi)); + return (HMODULE)mbi.AllocationBase; +} diff --git a/src/osd/windows/winutil.h b/src/osd/windows/winutil.h index 7a469a2807f..c8d1190b6a8 100644 --- a/src/osd/windows/winutil.h +++ b/src/osd/windows/winutil.h @@ -15,5 +15,6 @@ file_error win_error_to_file_error(DWORD error); osd_dir_entry_type win_attributes_to_entry_type(DWORD attributes); BOOL win_is_gui_application(void); +HMODULE WINAPI GetModuleHandleUni(); #endif // __WINUTIL__ From 5a36c4380024e42d7c5bd68e09f4a3f347755a28 Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Wed, 26 Aug 2015 10:04:41 +0300 Subject: [PATCH 2/8] Fixed GetModuleHandleUni --- src/osd/windows/winutil.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/osd/windows/winutil.c b/src/osd/windows/winutil.c index c778f0b604b..f4cf0a24e6c 100644 --- a/src/osd/windows/winutil.c +++ b/src/osd/windows/winutil.c @@ -130,7 +130,6 @@ BOOL win_is_gui_application(void) HMODULE WINAPI GetModuleHandleUni() { MEMORY_BASIC_INFORMATION mbi; - static int dummy; - VirtualQuery(&dummy, &mbi, sizeof(mbi)); + VirtualQuery(GetModuleHandleUni, &mbi, sizeof(mbi)); return (HMODULE)mbi.AllocationBase; } From 8b2b67d9e41b2164141ef6c41ead12719f206606 Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Wed, 26 Aug 2015 11:56:49 +0300 Subject: [PATCH 3/8] Fixed GetModuleHandleUni VirtualQuery first argument fixed. --- src/osd/windows/winutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osd/windows/winutil.c b/src/osd/windows/winutil.c index f4cf0a24e6c..c34e358492b 100644 --- a/src/osd/windows/winutil.c +++ b/src/osd/windows/winutil.c @@ -130,6 +130,6 @@ BOOL win_is_gui_application(void) HMODULE WINAPI GetModuleHandleUni() { MEMORY_BASIC_INFORMATION mbi; - VirtualQuery(GetModuleHandleUni, &mbi, sizeof(mbi)); + VirtualQuery((LPCVOID)GetModuleHandleUni, &mbi, sizeof(mbi)); return (HMODULE)mbi.AllocationBase; } From 40b357731be8194b55a29cfaf169e60260c6989a Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Thu, 27 Aug 2015 14:05:59 +0300 Subject: [PATCH 4/8] Fixed register_window_class First, try to unregister previously registered class. --- src/osd/modules/debugger/win/debugviewinfo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/osd/modules/debugger/win/debugviewinfo.c b/src/osd/modules/debugger/win/debugviewinfo.c index 504c90f2bf1..abdddcec931 100644 --- a/src/osd/modules/debugger/win/debugviewinfo.c +++ b/src/osd/modules/debugger/win/debugviewinfo.c @@ -800,6 +800,8 @@ void debugview_info::register_window_class() wc.style = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; + + UnregisterClass(wc.lpszClassName, wc.hInstance); // register the class; fail if we can't if (!RegisterClass(&wc)) From d1c123beeb79a9817743e7597fff38a05a9d7599 Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Thu, 27 Aug 2015 14:07:13 +0300 Subject: [PATCH 5/8] Fixed register_window_class First, try to unregister previously registered class. --- src/osd/modules/debugger/win/debugwininfo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/osd/modules/debugger/win/debugwininfo.c b/src/osd/modules/debugger/win/debugwininfo.c index fd6c4fdb099..4a8223f39fb 100644 --- a/src/osd/modules/debugger/win/debugwininfo.c +++ b/src/osd/modules/debugger/win/debugwininfo.c @@ -591,6 +591,8 @@ void debugwin_info::register_window_class() wc.style = 0; wc.cbClsExtra = 0; wc.cbWndExtra = 0; + + UnregisterClass(wc.lpszClassName, wc.hInstance); // register the class; fail if we can't if (!RegisterClass(&wc)) From ee826f16cbced0edc825cb19e89ee464535283db Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Thu, 27 Aug 2015 14:08:38 +0300 Subject: [PATCH 6/8] Fixed register_window_classcreate_window_class First, try to unregister previously registered class. --- src/osd/windows/output.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/osd/windows/output.c b/src/osd/windows/output.c index ae6ea535334..7c7dbe35484 100644 --- a/src/osd/windows/output.c +++ b/src/osd/windows/output.c @@ -171,6 +171,8 @@ static int create_window_class(void) wc.lpszClassName = OUTPUT_WINDOW_CLASS; wc.hInstance = GetModuleHandleUni(); wc.lpfnWndProc = output_window_proc; + + UnregisterClass(wc.lpszClassName, wc.hInstance); // register the class; fail if we can't if (!RegisterClass(&wc)) From d7cf28647acc9eb241aa04f13a2a71ecfe83e018 Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Thu, 27 Aug 2015 14:10:21 +0300 Subject: [PATCH 7/8] Fixed create_window_class First, try to unregister previously registered class. --- src/osd/windows/window.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/osd/windows/window.c b/src/osd/windows/window.c index a16a39286b8..1c11e960c4e 100644 --- a/src/osd/windows/window.c +++ b/src/osd/windows/window.c @@ -891,6 +891,8 @@ static void create_window_class(void) wc.lpfnWndProc = winwindow_video_window_proc_ui; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(wc.hInstance, MAKEINTRESOURCE(2)); + + UnregisterClass(wc.lpszClassName, wc.hInstance); // register the class; fail if we can't if (!RegisterClass(&wc)) @@ -1393,7 +1395,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR break; } return DefWindowProc(wnd, message, wparam, lparam); - } + }c // track whether we are in the foreground case WM_ACTIVATEAPP: From 27f3177dda003b5a7ba5639889a99c80b9935d51 Mon Sep 17 00:00:00 2001 From: Vladimir Kryvian Date: Thu, 27 Aug 2015 15:06:01 +0300 Subject: [PATCH 8/8] Update window.c Just a mistype. --- src/osd/windows/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/osd/windows/window.c b/src/osd/windows/window.c index 1c11e960c4e..94a0a69ea94 100644 --- a/src/osd/windows/window.c +++ b/src/osd/windows/window.c @@ -1395,7 +1395,7 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR break; } return DefWindowProc(wnd, message, wparam, lparam); - }c + } // track whether we are in the foreground case WM_ACTIVATEAPP: