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

Annotation of /trunk/src/GPGOE.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (hide annotations)
Fri Apr 7 10:46:41 2006 UTC (19 years, 1 month ago) by twoaday
File MIME type: text/plain
File size: 4125 byte(s)


1 twoaday 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 twoaday 12 /* Quick and dirty check if the dialog is a common dialog
69     and the 'File Save' style. */
70     static int
71     is_filesave_dlg (HWND h)
72     {
73     HWND button = GetDlgItem (h, 1040);
74     char wclass[200];
75    
76     if (button == NULL)
77     return 0;
78     if (GetClassName (button, wclass, 200) > 0
79     && !stricmp (wclass, "Button"))
80     return -1;
81     return 0;
82     }
83    
84    
85 twoaday 1 /* CTB hook procedure.
86     Monitors the creation of all windows and subclass the window
87     if it belongs to the Outlook Express message class. */
88     static LRESULT CALLBACK
89     ctb_proc (int code, WPARAM wparam, LPARAM lparam)
90     {
91     HWND hwnd;
92     char wclass[256];
93    
94     if (code < 0)
95     return CallNextHookEx (ctb_hook, code, wparam, lparam);
96    
97     hwnd = (HWND)wparam;
98     switch (code) {
99     case HCBT_CREATEWND:
100     GetClassName (hwnd, wclass, sizeof (wclass) - 1);
101     if (!strcmp (wclass, "ATH_Note")) {
102     oe_proc_old = (WNDPROC) GetWindowLong (hwnd, GWL_WNDPROC);
103     if (!oe_proc_old)
104     show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
105     "Could not get window procedure ec=%d",
106     (int)GetLastError ());
107     else if (!SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc))
108     show_error (NULL, "GPGOE", MB_ICONERROR|MB_OK,
109     "Could not set window procedure: ec=%d",
110     (int)GetLastError ());
111     else
112     oe_hwnd = hwnd;
113     }
114     break;
115 twoaday 12
116     #if 0
117     case HCBT_ACTIVATE:
118     if (plugin_active != NULL &&
119     WaitForSingleObject (plugin_active, 0) == WAIT_OBJECT_0) {
120     char wclass[200];
121    
122     if (GetClassName (hwnd, wclass, sizeof (wclass)-1) <= 0 ||
123     !strstr (wclass, "#32770") || !is_filesave_dlg (hwnd))
124     break;
125     of_proc_old = (WNDPROC)GetWindowLong (hwnd, GWL_WNDPROC);
126     SetWindowLong (hwnd, GWL_WNDPROC, (LONG)(WNDPROC)of_proc);
127     }
128     break;
129     #endif
130 twoaday 1 }
131     return CallNextHookEx (ctb_hook, code, wparam, lparam);
132     }
133    
134    
135     /* Initialize the hooks.
136     To prevent double initialisation, we use a named mutex. */
137     int
138     gpgoe_initialize (void)
139     {
140     CreateMutex (NULL, TRUE, "gpgoe");
141     if (GetLastError () == ERROR_ALREADY_EXISTS)
142     return 0;
143     ctb_hook = SetWindowsHookEx (WH_CBT, ctb_proc, mod_hinst_dll, 0);
144     return ctb_hook? 0 : (int)GetLastError ();
145     }
146    
147    
148     /* Deinitialize the hooks and close all handles. */
149     int
150     gpgoe_remove (void)
151     {
152     int rc = 0;
153     HANDLE hd;
154    
155     hd = CreateMutex (NULL, TRUE, "gpgoe");
156     if (GetLastError() == ERROR_ALREADY_EXISTS) {
157     oe_hwnd = NULL;
158     CloseHandle (hd);
159     }
160     SetWindowLong (oe_hwnd, GWL_WNDPROC, (LONG)(WNDPROC)oe_proc_old);
161     rc = UnhookWindowsHookEx (ctb_hook);
162     return rc ? 0 : (int)GetLastError ();
163     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26