/[gpgoe]/trunk/src/GPGOE.c
ViewVC logotype

Contents of /trunk/src/GPGOE.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Fri Mar 24 13:36:54 2006 UTC (19 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 3362 byte(s)
Initial checkin of the GPGOE code.


1 /* GPGOE.c - GnuPG for Outlook Express
2 * Copyright (C) 2001, 2002, 2003, 2006 Timo Schulz
3 *
4 * This file is part of GPGOE.
5 *
6 * GPGOE is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * GPGOE is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with GPGOE; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <windows.h>
26 #include <stdio.h>
27 #include "gpgme.h"
28 #include "GPGOE.h"
29
30
31 /* Global DLL module handle. */
32 HINSTANCE mod_hinst_dll;
33
34 /* DLL hook handle for the CBT function. */
35 static HHOOK ctb_hook = NULL;
36
37 /* Outlook Express window handle. */
38 static HWND oe_hwnd = NULL;
39
40 /* Outlook Express old window procedure. */
41 WNDPROC oe_proc_old;
42
43
44 /* Main DLL entry point. */
45 BOOL WINAPI
46 DllMain (HINSTANCE hinst_dll, DWORD reason, LPVOID reserved)
47 {
48 switch (reason) {
49 case DLL_PROCESS_ATTACH:
50 mod_hinst_dll = hinst_dll;
51 break;
52
53 case DLL_PROCESS_DETACH:
54 mod_hinst_dll = NULL;
55 break;
56
57 case DLL_THREAD_ATTACH:
58 break;
59
60 case DLL_THREAD_DETACH:
61 break;
62 }
63
64 return TRUE;
65 }
66
67
68 /* CTB hook procedure.
69 Monitors the creation of all windows and subclass the window
70 if it belongs to the Outlook Express message class. */
71 static LRESULT CALLBACK
72 ctb_proc (int code, WPARAM wparam, LPARAM lparam)
73 {
74 HWND hwnd;
75 char wclass[256];
76
77 if (code < 0)
78 return CallNextHookEx (ctb_hook, code, wparam, lparam);
79
80 hwnd = (HWND)wparam;
81 switch (code) {
82 case HCBT_CREATEWND:
83 GetClassName (hwnd, wclass, sizeof (wclass) - 1);
84 if (!strcmp (wclass, "ATH_Note")) {
85 oe_proc_old = (WNDPROC) GetWindowLong (hwnd, GWL_WNDPROC);
86 if (!oe_proc_old)
87 show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
88 "Could not get window procedure ec=%d",
89 (int)GetLastError ());
90 else if (!SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc))
91 show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
92 "Could not set window procedure: ec=%d",
93 (int)GetLastError ());
94 else
95 oe_hwnd = hwnd;
96 }
97 break;
98 }
99 return CallNextHookEx (ctb_hook, code, wparam, lparam);
100 }
101
102
103 /* Initialize the hooks.
104 To prevent double initialisation, we use a named mutex. */
105 int
106 gpgoe_initialize (void)
107 {
108 CreateMutex (NULL, TRUE, "gpgoe");
109 if (GetLastError () == ERROR_ALREADY_EXISTS)
110 return 0;
111 ctb_hook = SetWindowsHookEx (WH_CBT, ctb_proc, mod_hinst_dll, 0);
112 return ctb_hook? 0 : (int)GetLastError ();
113 }
114
115
116 /* Deinitialize the hooks and close all handles. */
117 int
118 gpgoe_remove (void)
119 {
120 int rc = 0;
121 HANDLE hd;
122
123 hd = CreateMutex (NULL, TRUE, "gpgoe");
124 if (GetLastError() == ERROR_ALREADY_EXISTS) {
125 oe_hwnd = NULL;
126 CloseHandle (hd);
127 }
128 SetWindowLong (oe_hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc_old);
129 rc = UnhookWindowsHookEx (ctb_hook);
130 return rc ? 0 : (int)GetLastError ();
131 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26