aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBen Key2002-12-18 06:16:28 +0000
committerBen Key2002-12-18 06:16:28 +0000
commit9785d95b98c184d5051775555e5af0b707a5ce9a (patch)
tree3685b3a963b97270c8512dbc8fe38140c0464212 /src
parent250465030318621ed461d261e7807bf25b2f90b1 (diff)
downloademacs-9785d95b98c184d5051775555e5af0b707a5ce9a.tar.gz
emacs-9785d95b98c184d5051775555e5af0b707a5ce9a.zip
Revisited my earlier fix for the following entry in etc/PROBLEMS: 'Emacs built on Windows 9x/ME crashes at startup on Windows XP, or Emacs builtpart of on XP crashes at startup on Windows 9x/ME.' Fixed several Windows API errors detected by BoundsChecker
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog85
-rw-r--r--src/emacs.c12
-rw-r--r--src/w32.c107
-rw-r--r--src/w32.h3
-rw-r--r--src/w32fns.c55
-rw-r--r--src/w32menu.c43
-rw-r--r--src/w32term.c12
7 files changed, 226 insertions, 91 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index ae7f9788233..f7fc7bb1253 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,88 @@
12002-12-17 Ben Key <bkey1@tampabay.rr.com>
2 * Revisited my earlier fix for the following entry in
3 etc/PROBLEMS:
4 "Emacs built on Windows 9x/ME crashes at startup on Windows XP,
5 or Emacs builtpart of on XP crashes at startup on Windows 9x/ME."
6
7 These changes were in part based upon suggestions made by Peter
8 'Luna' Runestig [peter@runestig.com].
9
10 * w32.c (g_b_init_is_windows_9x, g_b_init_open_process_token,
11 g_b_init_get_token_information, g_b_init_lookup_account_sid,
12 g_b_init_get_sid_identifier_authority ): Added several static
13 global variables.
14
15 * w32.c (globals_of_w32): New function. Used to initialize those
16 global variables that must always be initialized on startup even
17 when the global variable initialized is non zero. Its primary
18 purpose at this time is to set the global variables
19 g_b_init_is_windows_9x, g_b_init_open_process_token,
20 g_b_init_get_token_information, g_b_init_lookup_account_sid, and
21 g_b_init_get_sid_identifier_authority to 0 on startup. Called
22 from main.
23
24 * w32.c (is_windows_9x): Perform initialization only if
25 g_b_init_is_windows_9x is equal to 0. On initialization set
26 g_b_init_is_windows_9x equal to 1.
27
28 * w32.c (open_process_token): Perform initialization only if
29 g_b_init_open_process_token is equal to 0. On initialization set
30 g_b_init_open_process_token equal to 1.
31
32 * w32.c (get_token_information): Perform initialization only if
33 g_b_init_get_token_information is equal to 0. On initialization
34 set g_b_init_get_token_information equal to 1.
35
36 * w32.c (lookup_account_sid): Perform initialization only if
37 g_b_init_lookup_account_sid is equal to 0. On initialization
38 set g_b_init_lookup_account_sid equal to 1.
39
40 * w32.c (get_sid_identifier_authority): Perform initialization
41 only if g_b_init_get_sid_identifier_authority is equal to 0. On
42 initialization set g_b_init_get_sid_identifier_authority equal to
43 1.
44
45 * w32fns.c (globals_of_w32fns): New function. Used to initialize
46 those global variables that must always be initialized on startup
47 even when the global variable initialized is non zero. Its
48 primary purpose at this time is to initialize the global variable
49 track_mouse_event_fn.
50
51 * w32fns.c (w32_wnd_proc): Remove initialization of
52 track_mouse_event_fn from the handler for the WM_SETFOCUS
53 message.
54
55 * w32fns.c (syms_of_w32fns): Call globals_of_w32fns.
56
57 * w32menu.c (globals_of_w32menu): New function. Used to
58 initialize those global variables that must always be initialized
59 on startup even when the global variable initialized is non zero.
60 Its primary purpose at this time is to initialize the global
61 variables get_menu_item_info and set_menu_item_info.
62
63 * w32menu.c (initialize_frame_menubar): Remove initialization of
64 get_menu_item_info and set_menu_item_info.
65
66 * w32menu.c (syms_of_w32menu): Call globals_of_w32menu.
67
68 * w32.h (globals_of_w32, globals_of_w32fns, globals_of_w32menu):
69 Declare them.
70
71 * emacs.c (main): Call globals_of_w32 prior to calling
72 init_environment if WINDOWSNT is defined. Call globals_of_w32fns
73 and globals_of_w32menu if initialized is non zero and HAVE_NTGUI
74 is defined.
75
76 * w32term.c (x_update_window_begin): Fix Windows API error
77 detected by BoundsChecker. Test to determine if
78 w32_system_caret_hwnd is NULL prior to attempting to use
79 SendMessage to send the WM_EMACS_HIDE_CARET message to it.
80
81 * w32term.c (x_update_window_end): Fix Windows API error
82 detected by BoundsChecker. Test to determine if
83 w32_system_caret_hwnd is NULL prior to attempting to use
84 SendMessage to send the WM_EMACS_SHOW_CARET message to it.
85
12002-12-17 Kenichi Handa <handa@m17n.org> 862002-12-17 Kenichi Handa <handa@m17n.org>
2 87
3 * coding.c (coding_system_require_warning): New variable. 88 * coding.c (coding_system_require_warning): New variable.
diff --git a/src/emacs.c b/src/emacs.c
index 7bbaac8f923..7b5830c06a0 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1375,6 +1375,7 @@ main (argc, argv
1375#endif /* MSDOS */ 1375#endif /* MSDOS */
1376 1376
1377#ifdef WINDOWSNT 1377#ifdef WINDOWSNT
1378 globals_of_w32 ();
1378 /* Initialize environment from registry settings. */ 1379 /* Initialize environment from registry settings. */
1379 init_environment (argv); 1380 init_environment (argv);
1380 init_ntproc (); /* must precede init_editfns. */ 1381 init_ntproc (); /* must precede init_editfns. */
@@ -1541,6 +1542,17 @@ main (argc, argv
1541 keys_of_minibuf (); 1542 keys_of_minibuf ();
1542 keys_of_window (); 1543 keys_of_window ();
1543 } 1544 }
1545 else
1546 {
1547 /*
1548 Initialization that must be done even if the global variable
1549 initialized is non zero
1550 */
1551#ifdef HAVE_NTGUI
1552 globals_of_w32fns ();
1553 globals_of_w32menu ();
1554#endif /* end #ifdef HAVE_NTGUI */
1555 }
1544 1556
1545 if (!noninteractive) 1557 if (!noninteractive)
1546 { 1558 {
diff --git a/src/w32.c b/src/w32.c
index a608aad36f4..57b0e28d0ca 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -99,6 +99,8 @@ Boston, MA 02111-1307, USA.
99#include "w32heap.h" 99#include "w32heap.h"
100#include "systime.h" 100#include "systime.h"
101 101
102void globals_of_w32 ();
103
102extern Lisp_Object Vw32_downcase_file_names; 104extern Lisp_Object Vw32_downcase_file_names;
103extern Lisp_Object Vw32_generate_fake_inodes; 105extern Lisp_Object Vw32_generate_fake_inodes;
104extern Lisp_Object Vw32_get_true_file_attributes; 106extern Lisp_Object Vw32_get_true_file_attributes;
@@ -106,6 +108,15 @@ extern Lisp_Object Vw32_num_mouse_buttons;
106 108
107 109
108/* 110/*
111 Initialization states
112 */
113static BOOL g_b_init_is_windows_9x;
114static BOOL g_b_init_open_process_token;
115static BOOL g_b_init_get_token_information;
116static BOOL g_b_init_lookup_account_sid;
117static BOOL g_b_init_get_sid_identifier_authority;
118
119/*
109 BEGIN: Wrapper functions around OpenProcessToken 120 BEGIN: Wrapper functions around OpenProcessToken
110 and other functions in advapi32.dll that are only 121 and other functions in advapi32.dll that are only
111 supported in Windows NT / 2k / XP 122 supported in Windows NT / 2k / XP
@@ -140,15 +151,19 @@ typedef PSID_IDENTIFIER_AUTHORITY (WINAPI * GetSidIdentifierAuthority_Proc) (
140 /* ** A utility function ** */ 151 /* ** A utility function ** */
141static BOOL is_windows_9x () 152static BOOL is_windows_9x ()
142{ 153{
143 BOOL b_ret=0; 154 static BOOL s_b_ret=0;
144 OSVERSIONINFO os_ver; 155 OSVERSIONINFO os_ver;
145 ZeroMemory(&os_ver, sizeof(OSVERSIONINFO)); 156 if (g_b_init_is_windows_9x == 0)
146 os_ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
147 if (GetVersionEx (&os_ver))
148 { 157 {
149 b_ret = (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); 158 g_b_init_is_windows_9x = 1;
159 ZeroMemory(&os_ver, sizeof(OSVERSIONINFO));
160 os_ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
161 if (GetVersionEx (&os_ver))
162 {
163 s_b_ret = (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
164 }
150 } 165 }
151 return b_ret; 166 return s_b_ret;
152} 167}
153 168
154 /* ** The wrapper functions ** */ 169 /* ** The wrapper functions ** */
@@ -158,21 +173,25 @@ BOOL WINAPI open_process_token (
158 DWORD DesiredAccess, 173 DWORD DesiredAccess,
159 PHANDLE TokenHandle) 174 PHANDLE TokenHandle)
160{ 175{
161 OpenProcessToken_Proc pfn_Open_Process_Token = NULL; 176 static OpenProcessToken_Proc s_pfn_Open_Process_Token = NULL;
162 HMODULE hm_advapi32 = NULL; 177 HMODULE hm_advapi32 = NULL;
163 if (is_windows_9x () == TRUE) 178 if (is_windows_9x () == TRUE)
164 { 179 {
165 return FALSE; 180 return FALSE;
166 } 181 }
167 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 182 if (g_b_init_open_process_token == 0)
168 pfn_Open_Process_Token = 183 {
169 (OpenProcessToken_Proc) GetProcAddress (hm_advapi32, "OpenProcessToken"); 184 g_b_init_open_process_token = 1;
170 if (pfn_Open_Process_Token == NULL) 185 hm_advapi32 = LoadLibrary ("Advapi32.dll");
186 s_pfn_Open_Process_Token =
187 (OpenProcessToken_Proc) GetProcAddress (hm_advapi32, "OpenProcessToken");
188 }
189 if (s_pfn_Open_Process_Token == NULL)
171 { 190 {
172 return FALSE; 191 return FALSE;
173 } 192 }
174 return ( 193 return (
175 pfn_Open_Process_Token ( 194 s_pfn_Open_Process_Token (
176 ProcessHandle, 195 ProcessHandle,
177 DesiredAccess, 196 DesiredAccess,
178 TokenHandle) 197 TokenHandle)
@@ -186,21 +205,25 @@ BOOL WINAPI get_token_information (
186 DWORD TokenInformationLength, 205 DWORD TokenInformationLength,
187 PDWORD ReturnLength) 206 PDWORD ReturnLength)
188{ 207{
189 GetTokenInformation_Proc pfn_Get_Token_Information = NULL; 208 static GetTokenInformation_Proc s_pfn_Get_Token_Information = NULL;
190 HMODULE hm_advapi32 = NULL; 209 HMODULE hm_advapi32 = NULL;
191 if (is_windows_9x () == TRUE) 210 if (is_windows_9x () == TRUE)
192 { 211 {
193 return FALSE; 212 return FALSE;
194 } 213 }
195 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 214 if (g_b_init_get_token_information == 0)
196 pfn_Get_Token_Information = 215 {
197 (GetTokenInformation_Proc) GetProcAddress (hm_advapi32, "GetTokenInformation"); 216 g_b_init_get_token_information = 1;
198 if (pfn_Get_Token_Information == NULL) 217 hm_advapi32 = LoadLibrary ("Advapi32.dll");
218 s_pfn_Get_Token_Information =
219 (GetTokenInformation_Proc) GetProcAddress (hm_advapi32, "GetTokenInformation");
220 }
221 if (s_pfn_Get_Token_Information == NULL)
199 { 222 {
200 return FALSE; 223 return FALSE;
201 } 224 }
202 return ( 225 return (
203 pfn_Get_Token_Information ( 226 s_pfn_Get_Token_Information (
204 TokenHandle, 227 TokenHandle,
205 TokenInformationClass, 228 TokenInformationClass,
206 TokenInformation, 229 TokenInformation,
@@ -218,21 +241,25 @@ BOOL WINAPI lookup_account_sid (
218 LPDWORD cbDomainName, 241 LPDWORD cbDomainName,
219 PSID_NAME_USE peUse) 242 PSID_NAME_USE peUse)
220{ 243{
221 LookupAccountSid_Proc pfn_Lookup_Account_Sid = NULL; 244 static LookupAccountSid_Proc s_pfn_Lookup_Account_Sid = NULL;
222 HMODULE hm_advapi32 = NULL; 245 HMODULE hm_advapi32 = NULL;
223 if (is_windows_9x () == TRUE) 246 if (is_windows_9x () == TRUE)
224 { 247 {
225 return FALSE; 248 return FALSE;
226 } 249 }
227 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 250 if (g_b_init_lookup_account_sid == 0)
228 pfn_Lookup_Account_Sid = 251 {
229 (LookupAccountSid_Proc) GetProcAddress (hm_advapi32, LookupAccountSid_Name); 252 g_b_init_lookup_account_sid = 1;
230 if (pfn_Lookup_Account_Sid == NULL) 253 hm_advapi32 = LoadLibrary ("Advapi32.dll");
254 s_pfn_Lookup_Account_Sid =
255 (LookupAccountSid_Proc) GetProcAddress (hm_advapi32, LookupAccountSid_Name);
256 }
257 if (s_pfn_Lookup_Account_Sid == NULL)
231 { 258 {
232 return FALSE; 259 return FALSE;
233 } 260 }
234 return ( 261 return (
235 pfn_Lookup_Account_Sid ( 262 s_pfn_Lookup_Account_Sid (
236 lpSystemName, 263 lpSystemName,
237 Sid, 264 Sid,
238 Name, 265 Name,
@@ -246,21 +273,25 @@ BOOL WINAPI lookup_account_sid (
246PSID_IDENTIFIER_AUTHORITY WINAPI get_sid_identifier_authority ( 273PSID_IDENTIFIER_AUTHORITY WINAPI get_sid_identifier_authority (
247 PSID pSid) 274 PSID pSid)
248{ 275{
249 GetSidIdentifierAuthority_Proc pfn_Get_Sid_Identifier_Authority = NULL; 276 static GetSidIdentifierAuthority_Proc s_pfn_Get_Sid_Identifier_Authority = NULL;
250 HMODULE hm_advapi32 = NULL; 277 HMODULE hm_advapi32 = NULL;
251 if (is_windows_9x () == TRUE) 278 if (is_windows_9x () == TRUE)
252 { 279 {
253 return NULL; 280 return NULL;
254 } 281 }
255 hm_advapi32 = LoadLibrary ("Advapi32.dll"); 282 if (g_b_init_get_sid_identifier_authority == 0)
256 pfn_Get_Sid_Identifier_Authority = 283 {
257 (GetSidIdentifierAuthority_Proc) GetProcAddress ( 284 g_b_init_get_sid_identifier_authority = 1;
258 hm_advapi32, "GetSidIdentifierAuthority"); 285 hm_advapi32 = LoadLibrary ("Advapi32.dll");
259 if (pfn_Get_Sid_Identifier_Authority == NULL) 286 s_pfn_Get_Sid_Identifier_Authority =
287 (GetSidIdentifierAuthority_Proc) GetProcAddress (
288 hm_advapi32, "GetSidIdentifierAuthority");
289 }
290 if (s_pfn_Get_Sid_Identifier_Authority == NULL)
260 { 291 {
261 return NULL; 292 return NULL;
262 } 293 }
263 return (pfn_Get_Sid_Identifier_Authority (pSid)); 294 return (s_pfn_Get_Sid_Identifier_Authority (pSid));
264} 295}
265 296
266/* 297/*
@@ -3909,4 +3940,18 @@ init_ntproc ()
3909 check_windows_init_file (); 3940 check_windows_init_file ();
3910} 3941}
3911 3942
3943/*
3944 globals_of_w32 is used to initialize those global variables that
3945 must always be initialized on startup even when the global variable
3946 initialized is non zero (see the function main in emacs.c).
3947*/
3948void globals_of_w32 ()
3949{
3950 g_b_init_is_windows_9x = 0;
3951 g_b_init_open_process_token = 0;
3952 g_b_init_get_token_information = 0;
3953 g_b_init_lookup_account_sid = 0;
3954 g_b_init_get_sid_identifier_authority = 0;
3955}
3956
3912/* end of nt.c */ 3957/* end of nt.c */
diff --git a/src/w32.h b/src/w32.h
index 24fda2c648b..c8733c41a26 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -124,10 +124,13 @@ extern LPBYTE w32_get_resource (char * key, LPDWORD type);
124 124
125extern void init_ntproc (); 125extern void init_ntproc ();
126extern void term_ntproc (); 126extern void term_ntproc ();
127extern void globals_of_w32 ();
127extern void syms_of_w32term (); 128extern void syms_of_w32term ();
128extern void syms_of_w32fns (); 129extern void syms_of_w32fns ();
130extern void globals_of_w32fns ();
129extern void syms_of_w32select (); 131extern void syms_of_w32select ();
130extern void syms_of_w32menu (); 132extern void syms_of_w32menu ();
133extern void globals_of_w32menu ();
131extern void syms_of_fontset (); 134extern void syms_of_fontset ();
132 135
133#endif /* EMACS_W32_H */ 136#endif /* EMACS_W32_H */
diff --git a/src/w32fns.c b/src/w32fns.c
index 86984597e99..08d81d10296 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -55,6 +55,9 @@ Boston, MA 02111-1307, USA. */
55#include <dlgs.h> 55#include <dlgs.h>
56#define FILE_NAME_TEXT_FIELD edt1 56#define FILE_NAME_TEXT_FIELD edt1
57 57
58void syms_of_w32fns ();
59void globals_of_w32fns ();
60
58extern void free_frame_menubar (); 61extern void free_frame_menubar ();
59extern void x_compute_fringe_widths P_ ((struct frame *, int)); 62extern void x_compute_fringe_widths P_ ((struct frame *, int));
60extern double atof (); 63extern double atof ();
@@ -4934,30 +4937,6 @@ w32_wnd_proc (hwnd, msg, wParam, lParam)
4934 goto dflt; 4937 goto dflt;
4935 4938
4936 case WM_SETFOCUS: 4939 case WM_SETFOCUS:
4937 /*
4938 Reinitialize the function pointer track_mouse_event_fn here.
4939 This is required even though it is initialized in syms_of_w32fns
4940 which is called in main (emacs.c).
4941 Reinitialize the function pointer track_mouse_event_fn here.
4942 Even though this function pointer is initialized in
4943 syms_of_w32fns which is called from main (emacs.c),
4944 we need to initialize it again here in order to prevent
4945 a crash that occurs in Windows 9x (possibly only when Emacs
4946 was built on Windows NT / 2000 / XP?) when handling the
4947 WM_MOUSEMOVE message.
4948 The crash occurs when attempting to call the Win32 API
4949 function TrackMouseEvent through the function pointer.
4950 It appears as if the function pointer that is obtained when
4951 syms_of_w32fns is called from main is no longer valid
4952 (possibly due to DLL relocation?).
4953 To resolve this issue, I have placed a call to reinitialize
4954 this function pointer here because this message gets received
4955 when the Emacs window gains focus.
4956 */
4957 track_mouse_event_fn =
4958 (TrackMouseEvent_Proc) GetProcAddress (
4959 GetModuleHandle ("user32.dll"),
4960 "TrackMouseEvent");
4961 dpyinfo->faked_key = 0; 4940 dpyinfo->faked_key = 0;
4962 reset_modifiers (); 4941 reset_modifiers ();
4963 register_hot_keys (hwnd); 4942 register_hot_keys (hwnd);
@@ -14906,14 +14885,9 @@ If the underlying system call fails, value is nil. */)
14906void 14885void
14907syms_of_w32fns () 14886syms_of_w32fns ()
14908{ 14887{
14909 HMODULE user32_lib = GetModuleHandle ("user32.dll"); 14888 globals_of_w32fns ();
14910 14889 /* This is zero if not using MS-Windows. */
14911 /* This is zero if not using MS-Windows. */
14912 w32_in_use = 0; 14890 w32_in_use = 0;
14913
14914 /* TrackMouseEvent not available in all versions of Windows, so must load
14915 it dynamically. Do it once, here, instead of every time it is used. */
14916 track_mouse_event_fn = (TrackMouseEvent_Proc) GetProcAddress (user32_lib, "TrackMouseEvent");
14917 track_mouse_window = NULL; 14891 track_mouse_window = NULL;
14918 14892
14919 w32_visible_system_caret_hwnd = NULL; 14893 w32_visible_system_caret_hwnd = NULL;
@@ -15496,7 +15470,26 @@ versions of Windows) characters. */);
15496 defsubr (&Sx_file_dialog); 15470 defsubr (&Sx_file_dialog);
15497} 15471}
15498 15472
15473
15474/*
15475 globals_of_w32fns is used to initialize those global variables that
15476 must always be initialized on startup even when the global variable
15477 initialized is non zero (see the function main in emacs.c).
15478 globals_of_w32fns is called from syms_of_w32fns when the global
15479 variable initialized is 0 and directly from main when initialized
15480 is non zero.
15481 */
15482void globals_of_w32fns ()
15483{
15484 HMODULE user32_lib = GetModuleHandle ("user32.dll");
15485 /*
15486 TrackMouseEvent not available in all versions of Windows, so must load
15487 it dynamically. Do it once, here, instead of every time it is used.
15488 */
15489 track_mouse_event_fn = (TrackMouseEvent_Proc) GetProcAddress (user32_lib, "TrackMouseEvent");
15490}
15499 15491
15492
15500void 15493void
15501init_xfns () 15494init_xfns ()
15502{ 15495{
diff --git a/src/w32menu.c b/src/w32menu.c
index 8139a0ad956..e573986b31c 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -130,6 +130,7 @@ typedef struct _widget_value
130static HMENU current_popup_menu; 130static HMENU current_popup_menu;
131 131
132void syms_of_w32menu (); 132void syms_of_w32menu ();
133void globals_of_w32menu ();
133 134
134typedef BOOL (WINAPI * GetMenuItemInfoA_Proc) ( 135typedef BOOL (WINAPI * GetMenuItemInfoA_Proc) (
135 IN HMENU, 136 IN HMENU,
@@ -1606,26 +1607,6 @@ void
1606initialize_frame_menubar (f) 1607initialize_frame_menubar (f)
1607 FRAME_PTR f; 1608 FRAME_PTR f;
1608{ 1609{
1609 HMODULE user32 = GetModuleHandle ("user32.dll");
1610 /*
1611 Reinitialize the function pointers set_menu_item_info and
1612 get_menu_item_info here.
1613 Even though these function pointers are initialized in
1614 syms_of_w32menu which is called from main (emacs.c),
1615 we need to initialize them again here in order to prevent
1616 a crash that occurs in Windows 9x (possibly only when Emacs
1617 was built on Windows NT / 2000 / XP?) in add_menu_item.
1618 The crash occurs when attempting to call the Win32 API
1619 function SetMenuItemInfo through the function pointer.
1620 It appears as if the function pointer that is obtained when
1621 syms_of_w32menu is called from main is no longer valid
1622 (possibly due to DLL relocation?).
1623 To resolve this issue, I have placed calls to reinitialize
1624 these function pointers here because this function is the
1625 entry point for menu creation.
1626 */
1627 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA");
1628 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA");
1629 /* This function is called before the first chance to redisplay 1610 /* This function is called before the first chance to redisplay
1630 the frame. It has to be, so the frame will have the right size. */ 1611 the frame. It has to be, so the frame will have the right size. */
1631 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f)); 1612 FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f));
@@ -2392,11 +2373,7 @@ w32_free_menu_strings (hwnd)
2392 2373
2393void syms_of_w32menu () 2374void syms_of_w32menu ()
2394{ 2375{
2395 /* See if Get/SetMenuItemInfo functions are available. */ 2376 globals_of_w32menu ();
2396 HMODULE user32 = GetModuleHandle ("user32.dll");
2397 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA");
2398 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA");
2399
2400 staticpro (&menu_items); 2377 staticpro (&menu_items);
2401 menu_items = Qnil; 2378 menu_items = Qnil;
2402 2379
@@ -2415,3 +2392,19 @@ The enable predicate for a menu command should check this variable. */);
2415 defsubr (&Sx_popup_dialog); 2392 defsubr (&Sx_popup_dialog);
2416#endif 2393#endif
2417} 2394}
2395
2396/*
2397 globals_of_w32menu is used to initialize those global variables that
2398 must always be initialized on startup even when the global variable
2399 initialized is non zero (see the function main in emacs.c).
2400 globals_of_w32menu is called from syms_of_w32menu when the global
2401 variable initialized is 0 and directly from main when initialized
2402 is non zero.
2403 */
2404void globals_of_w32menu ()
2405{
2406 /* See if Get/SetMenuItemInfo functions are available. */
2407 HMODULE user32 = GetModuleHandle ("user32.dll");
2408 get_menu_item_info = (GetMenuItemInfoA_Proc) GetProcAddress (user32, "GetMenuItemInfoA");
2409 set_menu_item_info = (SetMenuItemInfoA_Proc) GetProcAddress (user32, "SetMenuItemInfoA");
2410}
diff --git a/src/w32term.c b/src/w32term.c
index 73740b2555f..08b076df037 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -603,8 +603,10 @@ x_update_window_begin (w)
603 struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f); 603 struct w32_display_info *display_info = FRAME_W32_DISPLAY_INFO (f);
604 604
605 /* Hide the system caret during an update. */ 605 /* Hide the system caret during an update. */
606 if (w32_use_visible_system_caret) 606 if (w32_use_visible_system_caret && w32_system_caret_hwnd)
607 SendMessage (w32_system_caret_hwnd, WM_EMACS_HIDE_CARET, 0, 0); 607 {
608 SendMessage (w32_system_caret_hwnd, WM_EMACS_HIDE_CARET, 0, 0);
609 }
608 610
609 updated_window = w; 611 updated_window = w;
610 set_output_cursor (&w->cursor); 612 set_output_cursor (&w->cursor);
@@ -730,8 +732,10 @@ x_update_window_end (w, cursor_on_p, mouse_face_overwritten_p)
730 /* Unhide the caret. This won't actually show the cursor, unless it 732 /* Unhide the caret. This won't actually show the cursor, unless it
731 was visible before the corresponding call to HideCaret in 733 was visible before the corresponding call to HideCaret in
732 x_update_window_begin. */ 734 x_update_window_begin. */
733 if (w32_use_visible_system_caret) 735 if (w32_use_visible_system_caret && w32_system_caret_hwnd)
734 SendMessage (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0); 736 {
737 SendMessage (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0);
738 }
735 739
736 updated_window = NULL; 740 updated_window = NULL;
737} 741}