GdkWin32: Retrieve module HINSTANCE in static builds
This commit is contained in:
@ -69,6 +69,17 @@ _gdk_win32_windowing_init (void)
|
|||||||
if (gdk_synchronize)
|
if (gdk_synchronize)
|
||||||
GdiSetBatchLimit (1);
|
GdiSetBatchLimit (1);
|
||||||
|
|
||||||
|
#ifndef DLL_EXPORT
|
||||||
|
if (!GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||||
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||||
|
(LPCWSTR)_gdk_win32_windowing_init,
|
||||||
|
&_gdk_dll_hinstance))
|
||||||
|
{
|
||||||
|
g_error ("GetModuleHandleExW failed with error code %u\n",
|
||||||
|
(unsigned) GetLastError ());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
_gdk_app_hmodule = GetModuleHandle (NULL);
|
_gdk_app_hmodule = GetModuleHandle (NULL);
|
||||||
_gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
|
_gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
|
||||||
_gdk_input_locale = GetKeyboardLayout (0);
|
_gdk_input_locale = GetKeyboardLayout (0);
|
||||||
|
|||||||
@ -38,10 +38,9 @@
|
|||||||
*/
|
*/
|
||||||
#define EMPIRIC_MANIFEST_RESOURCE_INDEX 2
|
#define EMPIRIC_MANIFEST_RESOURCE_INDEX 2
|
||||||
|
|
||||||
|
#ifdef DLL_EXPORT
|
||||||
static HMODULE gtk_dll;
|
static HMODULE gtk_dll;
|
||||||
|
|
||||||
#ifdef DLL_EXPORT
|
|
||||||
BOOL WINAPI
|
BOOL WINAPI
|
||||||
DllMain (HINSTANCE hinstDLL,
|
DllMain (HINSTANCE hinstDLL,
|
||||||
DWORD fdwReason,
|
DWORD fdwReason,
|
||||||
@ -56,6 +55,32 @@ DllMain (HINSTANCE hinstDLL,
|
|||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static HMODULE
|
||||||
|
get_gtk_dll (void)
|
||||||
|
{
|
||||||
|
return gtk_dll;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
static HMODULE
|
||||||
|
get_gtk_dll (void)
|
||||||
|
{
|
||||||
|
static HMODULE gtk_dll = NULL;
|
||||||
|
|
||||||
|
if G_UNLIKELY (gtk_dll == NULL)
|
||||||
|
{
|
||||||
|
if (!GetModuleHandleExW (GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||||
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||||
|
(LPCWSTR) get_gtk_dll,
|
||||||
|
>k_dll))
|
||||||
|
{
|
||||||
|
g_error ("GetModuleHandleExW failed with error code %u\n",
|
||||||
|
(unsigned) GetLastError ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return gtk_dll;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static BOOL CALLBACK
|
static BOOL CALLBACK
|
||||||
@ -104,7 +129,8 @@ _gtk_load_dll_with_libgtk3_manifest (const gchar *dll_name)
|
|||||||
DWORD error_code;
|
DWORD error_code;
|
||||||
|
|
||||||
resource_name = NULL;
|
resource_name = NULL;
|
||||||
EnumResourceNames (gtk_dll, RT_MANIFEST, find_first_manifest,
|
EnumResourceNames (get_gtk_dll (), RT_MANIFEST,
|
||||||
|
find_first_manifest,
|
||||||
(LONG_PTR) &resource_name);
|
(LONG_PTR) &resource_name);
|
||||||
|
|
||||||
if (resource_name == NULL)
|
if (resource_name == NULL)
|
||||||
@ -115,7 +141,7 @@ _gtk_load_dll_with_libgtk3_manifest (const gchar *dll_name)
|
|||||||
activation_ctx_descriptor.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID |
|
activation_ctx_descriptor.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID |
|
||||||
ACTCTX_FLAG_HMODULE_VALID |
|
ACTCTX_FLAG_HMODULE_VALID |
|
||||||
ACTCTX_FLAG_SET_PROCESS_DEFAULT;
|
ACTCTX_FLAG_SET_PROCESS_DEFAULT;
|
||||||
activation_ctx_descriptor.hModule = gtk_dll;
|
activation_ctx_descriptor.hModule = get_gtk_dll ();
|
||||||
activation_ctx_descriptor.lpResourceName = resource_name;
|
activation_ctx_descriptor.lpResourceName = resource_name;
|
||||||
activation_ctx_handle = CreateActCtx (&activation_ctx_descriptor);
|
activation_ctx_handle = CreateActCtx (&activation_ctx_descriptor);
|
||||||
error_code = GetLastError ();
|
error_code = GetLastError ();
|
||||||
@ -123,7 +149,7 @@ _gtk_load_dll_with_libgtk3_manifest (const gchar *dll_name)
|
|||||||
if (activation_ctx_handle == INVALID_HANDLE_VALUE &&
|
if (activation_ctx_handle == INVALID_HANDLE_VALUE &&
|
||||||
error_code != ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET)
|
error_code != ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET)
|
||||||
g_warning ("Failed to CreateActCtx for module %p, resource %p: %lu",
|
g_warning ("Failed to CreateActCtx for module %p, resource %p: %lu",
|
||||||
gtk_dll, resource_name, GetLastError ());
|
get_gtk_dll (), resource_name, GetLastError ());
|
||||||
else if (error_code != ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET)
|
else if (error_code != ERROR_SXS_PROCESS_DEFAULT_ALREADY_SET)
|
||||||
{
|
{
|
||||||
activation_cookie = 0;
|
activation_cookie = 0;
|
||||||
@ -150,7 +176,7 @@ _gtk_get_libdir (void)
|
|||||||
static char *gtk_libdir = NULL;
|
static char *gtk_libdir = NULL;
|
||||||
if (gtk_libdir == NULL)
|
if (gtk_libdir == NULL)
|
||||||
{
|
{
|
||||||
gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
|
gchar *root = g_win32_get_package_installation_directory_of_module (get_gtk_dll ());
|
||||||
gchar *slash = strrchr (root, '\\');
|
gchar *slash = strrchr (root, '\\');
|
||||||
if (slash != NULL &&
|
if (slash != NULL &&
|
||||||
g_ascii_strcasecmp (slash + 1, ".libs") == 0)
|
g_ascii_strcasecmp (slash + 1, ".libs") == 0)
|
||||||
@ -181,7 +207,7 @@ _gtk_get_localedir (void)
|
|||||||
while (*--p != '/')
|
while (*--p != '/')
|
||||||
;
|
;
|
||||||
|
|
||||||
root = g_win32_get_package_installation_directory_of_module (gtk_dll);
|
root = g_win32_get_package_installation_directory_of_module (get_gtk_dll ());
|
||||||
temp = g_build_filename (root, p, NULL);
|
temp = g_build_filename (root, p, NULL);
|
||||||
g_free (root);
|
g_free (root);
|
||||||
|
|
||||||
@ -200,7 +226,7 @@ _gtk_get_datadir (void)
|
|||||||
static char *gtk_datadir = NULL;
|
static char *gtk_datadir = NULL;
|
||||||
if (gtk_datadir == NULL)
|
if (gtk_datadir == NULL)
|
||||||
{
|
{
|
||||||
gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
|
gchar *root = g_win32_get_package_installation_directory_of_module (get_gtk_dll ());
|
||||||
gtk_datadir = g_build_filename (root, "share", NULL);
|
gtk_datadir = g_build_filename (root, "share", NULL);
|
||||||
g_free (root);
|
g_free (root);
|
||||||
}
|
}
|
||||||
@ -214,7 +240,7 @@ _gtk_get_sysconfdir (void)
|
|||||||
static char *gtk_sysconfdir = NULL;
|
static char *gtk_sysconfdir = NULL;
|
||||||
if (gtk_sysconfdir == NULL)
|
if (gtk_sysconfdir == NULL)
|
||||||
{
|
{
|
||||||
gchar *root = g_win32_get_package_installation_directory_of_module (gtk_dll);
|
gchar *root = g_win32_get_package_installation_directory_of_module (get_gtk_dll ());
|
||||||
gtk_sysconfdir = g_build_filename (root, "etc", NULL);
|
gtk_sysconfdir = g_build_filename (root, "etc", NULL);
|
||||||
g_free (root);
|
g_free (root);
|
||||||
}
|
}
|
||||||
@ -227,7 +253,7 @@ _gtk_get_data_prefix (void)
|
|||||||
{
|
{
|
||||||
static char *gtk_data_prefix = NULL;
|
static char *gtk_data_prefix = NULL;
|
||||||
if (gtk_data_prefix == NULL)
|
if (gtk_data_prefix == NULL)
|
||||||
gtk_data_prefix = g_win32_get_package_installation_directory_of_module (gtk_dll);
|
gtk_data_prefix = g_win32_get_package_installation_directory_of_module (get_gtk_dll ());
|
||||||
|
|
||||||
return gtk_data_prefix;
|
return gtk_data_prefix;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user