Skip to content

Commit

Permalink
Move GPGME init from DLLMain to COM init
Browse files Browse the repository at this point in the history
* NEWS: Update.
* src/common.cpp (get_gpgme_w32_inst_dir): Move here from main.c
(set_global_hinstance): Removed for readability.
* src/common.h: Update accordingly.
* src/main.c (get_gpgme_w32_inst_dir): Move to common.cpp
(DllMain): Remove all initialization code.
* src/gpgoladdin.cpp (GpgolAddin::GpgolAddin): Do the
GPGME initalization here.

--
This does not functionally change anything but should probably
fix the "This addin caused a slow start of Outlook message".

GnuPG-Bug-Id: T6856
  • Loading branch information
AndreHeinecke committed Nov 29, 2023
1 parent 65de67d commit 8c015ef
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 54 deletions.
5 changes: 4 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Noteworthy changes for version 2.5.11 (unreleased)
Noteworthy changes for version 2.5.11 (2023-11-29)
==================================================

* Moved initialization code from DLL Load point to
COM initialization. (T6856)


Noteworthy changes for version 2.5.10 (2023-11-29)
==================================================
Expand Down
35 changes: 29 additions & 6 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@

HINSTANCE glob_hinst = NULL;

void
set_global_hinstance (HINSTANCE hinst)
{
glob_hinst = hinst;
}

void
bring_to_front (HWND wid)
{
Expand Down Expand Up @@ -1201,3 +1195,32 @@ compliance_string (bool forVerify, bool forDecrypt, bool isCompliant)
STRANGEPOINT;
return std::string();
}

char *
get_gpgme_w32_inst_dir (void)
{
char *gpg4win_dir = get_gpg4win_dir ();
char *tmp;
gpgrt_asprintf (&tmp, "%s\\bin\\gpgme-w32spawn.exe", gpg4win_dir);
memdbg_alloc (tmp);

if (!access(tmp, R_OK))
{
xfree (tmp);
gpgrt_asprintf (&tmp, "%s\\bin", gpg4win_dir);
memdbg_alloc (tmp);
xfree (gpg4win_dir);
return tmp;
}
xfree (tmp);
gpgrt_asprintf (&tmp, "%s\\gpgme-w32spawn.exe", gpg4win_dir);
memdbg_alloc (tmp);

if (!access(tmp, R_OK))
{
xfree (tmp);
return gpg4win_dir;
}
OutputDebugString("Failed to find gpgme-w32spawn.exe!");
return NULL;
}
5 changes: 2 additions & 3 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ extern "C" {
extern HINSTANCE glob_hinst;
extern UINT this_dll;

/*-- common.c --*/
void set_global_hinstance (HINSTANCE hinst);

/*-- common.cpp --*/
char *get_data_dir (void);
char *get_gpg4win_dir (void);
char *get_gpgme_w32_inst_dir (void);

int store_extension_value (const char *key, const char *val);
int store_extension_subkey_value (const char *subkey, const char *key,
Expand Down
17 changes: 17 additions & 0 deletions src/gpgoladdin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,28 @@ GpgolAddin::GpgolAddin (void) : m_lRef(0),
m_hook(nullptr),
m_dispcache(new DispCache)
{
/* Required first to start logging */
read_options ();
TRACEPOINT;
/* Start initialization */
gpg_err_init ();

/* Set the installation directory for GpgME so that
it can find tools like gpgme-w32-spawn correctly. */
char *instdir = get_gpgme_w32_inst_dir();
gpgme_set_global_flag ("w32-inst-dir", instdir);
xfree (instdir);

/* The next call initializes subsystems of gpgme and should be
done as early as possible. The actual return value (the
version string) is not used here. It may be called at any
time later for this. */
gpgme_check_version (NULL);
/* RibbonExtender is it's own object to avoid the pitfalls of
multiple inheritance
*/
m_ribbonExtender = new GpgolRibbonExtender();
TRACEPOINT;
}

GpgolAddin::~GpgolAddin (void)
Expand Down
47 changes: 3 additions & 44 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,6 @@ i18n_init (void)
textdomain (PACKAGE_GT);
}

static char *
get_gpgme_w32_inst_dir (void)
{
char *gpg4win_dir = get_gpg4win_dir ();
char *tmp;
gpgrt_asprintf (&tmp, "%s\\bin\\gpgme-w32spawn.exe", gpg4win_dir);
memdbg_alloc (tmp);

if (!access(tmp, R_OK))
{
xfree (tmp);
gpgrt_asprintf (&tmp, "%s\\bin", gpg4win_dir);
memdbg_alloc (tmp);
xfree (gpg4win_dir);
return tmp;
}
xfree (tmp);
gpgrt_asprintf (&tmp, "%s\\gpgme-w32spawn.exe", gpg4win_dir);
memdbg_alloc (tmp);

if (!access(tmp, R_OK))
{
xfree (tmp);
return gpg4win_dir;
}
OutputDebugString("Failed to find gpgme-w32spawn.exe!");
return NULL;
}

/* Entry point called by DLL loader. */
int WINAPI
DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved)
Expand All @@ -99,21 +70,9 @@ DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved)

if (reason == DLL_PROCESS_ATTACH)
{
set_global_hinstance (hinst);

gpg_err_init ();

/* Set the installation directory for GpgME so that
it can find tools like gpgme-w32-spawn correctly. */
char *instdir = get_gpgme_w32_inst_dir();
gpgme_set_global_flag ("w32-inst-dir", instdir);
xfree (instdir);

/* The next call initializes subsystems of gpgme and should be
done as early as possible. The actual return value (the
version string) is not used here. It may be called at any
time later for this. */
gpgme_check_version (NULL);
/* Do not do anything in here so Outlook does not blame us
for a slow start. (See Screenshot in T6856 ) */
glob_hinst = hinst;
}
else if (reason == DLL_PROCESS_DETACH)
{
Expand Down

0 comments on commit 8c015ef

Please sign in to comment.