[PATCH 1/4] winemac: Move DllMain to separated file.
Jacek Caban
wine at gitlab.winehq.org
Wed Jun 1 08:15:59 CDT 2022
From: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
---
dlls/winemac.drv/Makefile.in | 1 +
dlls/winemac.drv/dllmain.c | 65 +++++++++++++++++++++++++++
dlls/winemac.drv/macdrv.h | 2 +
dlls/winemac.drv/macdrv_main.c | 82 +++++++++++++---------------------
dlls/winemac.drv/unixlib.h | 43 ++++++++++++++++++
5 files changed, 142 insertions(+), 51 deletions(-)
create mode 100644 dlls/winemac.drv/dllmain.c
create mode 100644 dlls/winemac.drv/unixlib.h
diff --git a/dlls/winemac.drv/Makefile.in b/dlls/winemac.drv/Makefile.in
index e345249aac7..06c654344d1 100644
--- a/dlls/winemac.drv/Makefile.in
+++ b/dlls/winemac.drv/Makefile.in
@@ -9,6 +9,7 @@ EXTRADLLFLAGS = -mcygwin
C_SRCS = \
clipboard.c \
display.c \
+ dllmain.c \
dragdrop.c \
event.c \
gdi.c \
diff --git a/dlls/winemac.drv/dllmain.c b/dlls/winemac.drv/dllmain.c
new file mode 100644
index 00000000000..60ca50474d7
--- /dev/null
+++ b/dlls/winemac.drv/dllmain.c
@@ -0,0 +1,65 @@
+/*
+ * winemac.drv entry points
+ *
+ * Copyright 2022 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include <stdarg.h>
+#include "macdrv.h"
+
+
+HMODULE macdrv_module = 0;
+
+static BOOL process_attach(void)
+{
+ struct init_params params;
+
+ struct localized_string *str;
+ struct localized_string strings[] = {
+ { .id = STRING_MENU_WINE },
+ { .id = STRING_MENU_ITEM_HIDE_APPNAME },
+ { .id = STRING_MENU_ITEM_HIDE },
+ { .id = STRING_MENU_ITEM_HIDE_OTHERS },
+ { .id = STRING_MENU_ITEM_SHOW_ALL },
+ { .id = STRING_MENU_ITEM_QUIT_APPNAME },
+ { .id = STRING_MENU_ITEM_QUIT },
+
+ { .id = STRING_MENU_WINDOW },
+ { .id = STRING_MENU_ITEM_MINIMIZE },
+ { .id = STRING_MENU_ITEM_ZOOM },
+ { .id = STRING_MENU_ITEM_ENTER_FULL_SCREEN },
+ { .id = STRING_MENU_ITEM_BRING_ALL_TO_FRONT },
+
+ { .id = 0 }
+ };
+
+ for (str = strings; str->id; str++)
+ str->len = LoadStringW(macdrv_module, str->id, (WCHAR *)&str->str, 0);
+ params.strings = strings;
+
+ return !MACDRV_CALL(init, ¶ms);
+}
+
+BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, void *reserved)
+{
+ if (reason != DLL_PROCESS_ATTACH) return TRUE;
+
+ DisableThreadLibraryCalls(instance);
+ macdrv_module = instance;
+ return process_attach();
+}
diff --git a/dlls/winemac.drv/macdrv.h b/dlls/winemac.drv/macdrv.h
index 9cd0509a39c..39aff4d6a9f 100644
--- a/dlls/winemac.drv/macdrv.h
+++ b/dlls/winemac.drv/macdrv.h
@@ -33,6 +33,7 @@
#include "ntgdi.h"
#include "wine/debug.h"
#include "wine/gdi_driver.h"
+#include "unixlib.h"
extern BOOL skip_single_buffer_flushes DECLSPEC_HIDDEN;
@@ -280,6 +281,7 @@ extern void macdrv_status_item_mouse_move(const macdrv_event *event) DECLSPEC_HI
extern void check_retina_status(void) DECLSPEC_HIDDEN;
extern void macdrv_init_display_devices(BOOL force) DECLSPEC_HIDDEN;
extern void init_user_driver(void) DECLSPEC_HIDDEN;
+extern NTSTATUS macdrv_init(void *arg) DECLSPEC_HIDDEN;
/**************************************************************************
* Mac IME driver
diff --git a/dlls/winemac.drv/macdrv_main.c b/dlls/winemac.drv/macdrv_main.c
index a0dc9c494da..adcf6f73fc7 100644
--- a/dlls/winemac.drv/macdrv_main.c
+++ b/dlls/winemac.drv/macdrv_main.c
@@ -63,7 +63,6 @@ int cursor_clipping_locks_windows = TRUE;
int use_precise_scrolling = TRUE;
int gl_surface_mode = GL_SURFACE_IN_FRONT_OPAQUE;
int retina_enabled = FALSE;
-HMODULE macdrv_module = 0;
int enable_app_nap = FALSE;
CFDictionaryRef localized_strings;
@@ -396,25 +395,9 @@ static void setup_options(void)
/***********************************************************************
* load_strings
*/
-static void load_strings(HINSTANCE instance)
+static void load_strings(struct localized_string *str)
{
- static const unsigned int ids[] = {
- STRING_MENU_WINE,
- STRING_MENU_ITEM_HIDE_APPNAME,
- STRING_MENU_ITEM_HIDE,
- STRING_MENU_ITEM_HIDE_OTHERS,
- STRING_MENU_ITEM_SHOW_ALL,
- STRING_MENU_ITEM_QUIT_APPNAME,
- STRING_MENU_ITEM_QUIT,
-
- STRING_MENU_WINDOW,
- STRING_MENU_ITEM_MINIMIZE,
- STRING_MENU_ITEM_ZOOM,
- STRING_MENU_ITEM_ENTER_FULL_SCREEN,
- STRING_MENU_ITEM_BRING_ALL_TO_FRONT,
- };
CFMutableDictionaryRef dict;
- int i;
dict = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
@@ -424,21 +407,20 @@ static void load_strings(HINSTANCE instance)
return;
}
- for (i = 0; i < ARRAY_SIZE(ids); i++)
+ while (str->id)
{
- LPCWSTR str;
- int len = LoadStringW(instance, ids[i], (LPWSTR)&str, 0);
- if (str && len)
+ if (str->str && str->len)
{
- CFNumberRef key = CFNumberCreate(NULL, kCFNumberIntType, &ids[i]);
- CFStringRef value = CFStringCreateWithCharacters(NULL, (UniChar*)str, len);
+ CFNumberRef key = CFNumberCreate(NULL, kCFNumberIntType, &str->id);
+ CFStringRef value = CFStringCreateWithCharacters(NULL, (UniChar*)str->str, str->len);
if (key && value)
CFDictionarySetValue(dict, key, value);
else
- ERR("Failed to add string ID 0x%04x %s\n", ids[i], debugstr_wn(str, len));
+ ERR("Failed to add string ID 0x%04x %s\n", str->id, debugstr_wn(str->str, str->len));
}
else
- ERR("Failed to load string ID 0x%04x\n", ids[i]);
+ ERR("Failed to load string ID 0x%04x\n", str->id);
+ str++;
}
localized_strings = dict;
@@ -446,32 +428,33 @@ static void load_strings(HINSTANCE instance)
/***********************************************************************
- * process_attach
+ * macdrv_init
*/
-static BOOL process_attach(void)
+NTSTATUS macdrv_init(void *arg)
{
+ struct init_params *params = arg;
SessionAttributeBits attributes;
OSStatus status;
status = SessionGetInfo(callerSecuritySession, NULL, &attributes);
if (status != noErr || !(attributes & sessionHasGraphicAccess))
- return FALSE;
+ return STATUS_UNSUCCESSFUL;
init_win_context();
setup_options();
- load_strings(macdrv_module);
+ load_strings(params->strings);
macdrv_err_on = ERR_ON(macdrv);
- if (macdrv_start_cocoa_app(GetTickCount64()))
+ if (macdrv_start_cocoa_app(NtGetTickCount()))
{
ERR("Failed to start Cocoa app main loop\n");
- return FALSE;
+ return STATUS_UNSUCCESSFUL;
}
init_user_driver();
macdrv_init_display_devices(FALSE);
- return TRUE;
+ return STATUS_SUCCESS;
}
@@ -559,24 +542,6 @@ struct macdrv_thread_data *macdrv_init_thread_data(void)
}
-/***********************************************************************
- * DllMain
- */
-BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved)
-{
- BOOL ret = TRUE;
-
- switch(reason)
- {
- case DLL_PROCESS_ATTACH:
- DisableThreadLibraryCalls( hinst );
- macdrv_module = hinst;
- ret = process_attach();
- break;
- }
- return ret;
-}
-
/***********************************************************************
* SystemParametersInfo (MACDRV.@)
*/
@@ -640,3 +605,18 @@ BOOL macdrv_SystemParametersInfo( UINT action, UINT int_param, void *ptr_param,
}
return FALSE;
}
+
+
+const unixlib_entry_t __wine_unix_call_funcs[] =
+{
+ macdrv_init,
+};
+
+C_ASSERT( ARRAYSIZE(__wine_unix_call_funcs) == unix_funcs_count );
+
+
+/* FIXME: Use __wine_unix_call instead */
+NTSTATUS unix_call(enum macdrv_funcs code, void *params)
+{
+ return __wine_unix_call_funcs[code]( params );
+}
diff --git a/dlls/winemac.drv/unixlib.h b/dlls/winemac.drv/unixlib.h
new file mode 100644
index 00000000000..9f8cd4e0acb
--- /dev/null
+++ b/dlls/winemac.drv/unixlib.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2022 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "ntuser.h"
+#include "wine/unixlib.h"
+
+enum macdrv_funcs
+{
+ unix_init,
+ unix_funcs_count
+};
+
+/* FIXME: Use __wine_unix_call when the rest of the stack is ready */
+extern NTSTATUS unix_call(enum macdrv_funcs code, void *params) DECLSPEC_HIDDEN;
+#define MACDRV_CALL(func, params) unix_call( unix_ ## func, params )
+
+/* macdrv_init params */
+struct localized_string
+{
+ UINT id;
+ UINT len;
+ const WCHAR *str;
+};
+
+struct init_params
+{
+ struct localized_string *strings;
+};
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/168
More information about the wine-devel
mailing list