1 /*
2  * winstuff.h: Windows-specific inter-module stuff.
3  */
4 
5 #ifndef PUTTY_WINSTUFF_H
6 #define PUTTY_WINSTUFF_H
7 
8 #ifndef AUTO_WINSOCK
9 #include <winsock2.h>
10 #endif
11 #include <windows.h>
12 #include <stdio.h>                     /* for FILENAME_MAX */
13 
14 /* We use uintptr_t for Win32/Win64 portability, so we should in
15  * principle include stdint.h, which defines it according to the C
16  * standard. But older versions of Visual Studio - including the one
17  * used for official PuTTY builds as of 2015-09-28 - don't provide
18  * stdint.h at all, but do (non-standardly) define uintptr_t in
19  * stddef.h. So here we try to make sure _some_ standard header is
20  * included which defines uintptr_t. */
21 #include <stddef.h>
22 #if !defined _MSC_VER || _MSC_VER >= 1600 || defined __clang__
23 #include <stdint.h>
24 #endif
25 
26 #include "defs.h"
27 #include "marshal.h"
28 
29 #include "tree234.h"
30 
31 #include "winhelp.h"
32 
33 #if defined _M_IX86 || defined _M_AMD64
34 #define BUILDINFO_PLATFORM "x86 Windows"
35 #elif defined _M_ARM || defined _M_ARM64
36 #define BUILDINFO_PLATFORM "Arm Windows"
37 #else
38 #define BUILDINFO_PLATFORM "Windows"
39 #endif
40 
41 struct Filename {
42     char *path;
43 };
f_open(const Filename * filename,const char * mode,bool isprivate)44 static inline FILE *f_open(const Filename *filename, const char *mode,
45                            bool isprivate)
46 {
47     return fopen(filename->path, mode);
48 }
49 
50 struct FontSpec {
51     char *name;
52     bool isbold;
53     int height;
54     int charset;
55 };
56 struct FontSpec *fontspec_new(
57     const char *name, bool bold, int height, int charset);
58 
59 #ifndef CLEARTYPE_QUALITY
60 #define CLEARTYPE_QUALITY 5
61 #endif
62 #define FONT_QUALITY(fq) ( \
63     (fq) == FQ_DEFAULT ? DEFAULT_QUALITY : \
64     (fq) == FQ_ANTIALIASED ? ANTIALIASED_QUALITY : \
65     (fq) == FQ_NONANTIALIASED ? NONANTIALIASED_QUALITY : \
66     CLEARTYPE_QUALITY)
67 
68 #define PLATFORM_IS_UTF16 /* enable UTF-16 processing when exchanging
69                            * wchar_t strings with environment */
70 
71 #define PLATFORM_CLIPBOARDS(X)                      \
72     X(CLIP_SYSTEM, "system clipboard")              \
73     /* end of list */
74 
75 /*
76  * Where we can, we use GetWindowLongPtr and friends because they're
77  * more useful on 64-bit platforms, but they're a relatively recent
78  * innovation, missing from VC++ 6 and older MinGW.  Degrade nicely.
79  * (NB that on some systems, some of these things are available but
80  * not others...)
81  */
82 
83 #ifndef GCLP_HCURSOR
84 /* GetClassLongPtr and friends */
85 #undef  GetClassLongPtr
86 #define GetClassLongPtr GetClassLong
87 #undef  SetClassLongPtr
88 #define SetClassLongPtr SetClassLong
89 #define GCLP_HCURSOR GCL_HCURSOR
90 /* GetWindowLongPtr and friends */
91 #undef  GetWindowLongPtr
92 #define GetWindowLongPtr GetWindowLong
93 #undef  SetWindowLongPtr
94 #define SetWindowLongPtr SetWindowLong
95 #undef  GWLP_USERDATA
96 #define GWLP_USERDATA GWL_USERDATA
97 #undef  DWLP_MSGRESULT
98 #define DWLP_MSGRESULT DWL_MSGRESULT
99 /* Since we've clobbered the above functions, we should clobber the
100  * associated type regardless of whether it's defined. */
101 #undef LONG_PTR
102 #define LONG_PTR LONG
103 #endif
104 
105 #define BOXFLAGS DLGWINDOWEXTRA
106 #define BOXRESULT (DLGWINDOWEXTRA + sizeof(LONG_PTR))
107 #define DF_END 0x0001
108 
109 #ifndef __WINE__
110 /* Up-to-date Windows headers warn that the unprefixed versions of
111  * these names are deprecated. */
112 #define stricmp _stricmp
113 #define strnicmp _strnicmp
114 #else
115 /* Compiling with winegcc, _neither_ version of these functions
116  * exists. Use the POSIX names. */
117 #define stricmp strcasecmp
118 #define strnicmp strncasecmp
119 #endif
120 
121 #define BROKEN_PIPE_ERROR_CODE ERROR_BROKEN_PIPE   /* used in sshshare.c */
122 
123 /*
124  * Dynamically linked functions. These come in two flavours:
125  *
126  *  - GET_WINDOWS_FUNCTION does not expose "name" to the preprocessor,
127  *    so will always dynamically link against exactly what is specified
128  *    in "name". If you're not sure, use this one.
129  *
130  *  - GET_WINDOWS_FUNCTION_PP allows "name" to be redirected via
131  *    preprocessor definitions like "#define foo bar"; this is principally
132  *    intended for the ANSI/Unicode DoSomething/DoSomethingA/DoSomethingW.
133  *    If your function has an argument of type "LPTSTR" or similar, this
134  *    is the variant to use.
135  *    (However, it can't always be used, as it trips over more complicated
136  *    macro trickery such as the WspiapiGetAddrInfo wrapper for getaddrinfo.)
137  *
138  * (DECL_WINDOWS_FUNCTION works with both these variants.)
139  */
140 #define DECL_WINDOWS_FUNCTION(linkage, rettype, name, params)   \
141     typedef rettype (WINAPI *t_##name) params;                  \
142     linkage t_##name p_##name
143 /* If you DECL_WINDOWS_FUNCTION as extern in a header file, use this to
144  * define the function pointer in a source file */
145 #define DEF_WINDOWS_FUNCTION(name) t_##name p_##name
146 #define STR1(x) #x
147 #define STR(x) STR1(x)
148 #define GET_WINDOWS_FUNCTION_PP(module, name)                           \
149     TYPECHECK((t_##name)NULL == name,                                   \
150               (p_##name = module ?                                      \
151                (t_##name) GetProcAddress(module, STR(name)) : NULL))
152 #define GET_WINDOWS_FUNCTION(module, name)                              \
153     TYPECHECK((t_##name)NULL == name,                                   \
154               (p_##name = module ?                                      \
155                (t_##name) GetProcAddress(module, #name) : NULL))
156 #define GET_WINDOWS_FUNCTION_NO_TYPECHECK(module, name) \
157     (p_##name = module ?                                \
158      (t_##name) GetProcAddress(module, #name) : NULL)
159 
160 #define PUTTY_REG_POS "Software\\SimonTatham\\PuTTY"
161 #define PUTTY_REG_PARENT "Software\\SimonTatham"
162 #define PUTTY_REG_PARENT_CHILD "PuTTY"
163 #define PUTTY_REG_GPARENT "Software"
164 #define PUTTY_REG_GPARENT_CHILD "SimonTatham"
165 
166 /* Result values for the jumplist registry functions. */
167 #define JUMPLISTREG_OK 0
168 #define JUMPLISTREG_ERROR_INVALID_PARAMETER 1
169 #define JUMPLISTREG_ERROR_KEYOPENCREATE_FAILURE 2
170 #define JUMPLISTREG_ERROR_VALUEREAD_FAILURE 3
171 #define JUMPLISTREG_ERROR_VALUEWRITE_FAILURE 4
172 #define JUMPLISTREG_ERROR_INVALID_VALUE 5
173 
174 #define PUTTY_CHM_FILE "putty.chm"
175 
176 #define GETTICKCOUNT GetTickCount
177 #define CURSORBLINK GetCaretBlinkTime()
178 #define TICKSPERSEC 1000               /* GetTickCount returns milliseconds */
179 
180 #define DEFAULT_CODEPAGE CP_ACP
181 #define USES_VTLINE_HACK
182 
183 #ifndef NO_GSSAPI
184 /*
185  * GSS-API stuff
186  */
187 #define GSS_CC CALLBACK
188 /*
189 typedef struct Ssh_gss_buf {
190     size_t length;
191     char *value;
192 } Ssh_gss_buf;
193 
194 #define SSH_GSS_EMPTY_BUF (Ssh_gss_buf) {0,NULL}
195 typedef void *Ssh_gss_name;
196 */
197 #endif
198 
199 /*
200  * The all-important instance handle, saved from WinMain in every GUI
201  * program and exported for other GUI code to pass back to the Windows
202  * API.
203  */
204 extern HINSTANCE hinst;
205 
206 /*
207  * Help file stuff in winhelp.c.
208  */
209 void init_help(void);
210 void shutdown_help(void);
211 bool has_help(void);
212 void launch_help(HWND hwnd, const char *topic);
213 void quit_help(HWND hwnd);
214 int has_embedded_chm(void);            /* 1 = yes, 0 = no, -1 = N/A */
215 
216 /*
217  * GUI seat methods in windlg.c, so that the vtable definition in
218  * window.c can refer to them.
219  */
220 int win_seat_verify_ssh_host_key(
221     Seat *seat, const char *host, int port, const char *keytype,
222     char *keystr, const char *keydisp, char **key_fingerprints,
223     void (*callback)(void *ctx, int result), void *ctx);
224 int win_seat_confirm_weak_crypto_primitive(
225     Seat *seat, const char *algtype, const char *algname,
226     void (*callback)(void *ctx, int result), void *ctx);
227 int win_seat_confirm_weak_cached_hostkey(
228     Seat *seat, const char *algname, const char *betteralgs,
229     void (*callback)(void *ctx, int result), void *ctx);
230 
231 /*
232  * Windows-specific clipboard helper function shared with windlg.c,
233  * which takes the data string in the system code page instead of
234  * Unicode.
235  */
236 void write_aclip(int clipboard, char *, int, bool);
237 
238 #define WM_NETEVENT  (WM_APP + 5)
239 
240 /*
241  * On Windows, we send MA_2CLK as the only event marking the second
242  * press of a mouse button. Compare unix.h.
243  */
244 #define MULTICLICK_ONLY_EVENT 1
245 
246 /*
247  * On Windows, data written to the clipboard must be NUL-terminated.
248  */
249 #define SELECTION_NUL_TERMINATED 1
250 
251 /*
252  * On Windows, copying to the clipboard terminates lines with CRLF.
253  */
254 #define SEL_NL { 13, 10 }
255 
256 /*
257  * sk_getxdmdata() does not exist under Windows (not that I
258  * couldn't write it if I wanted to, but I haven't bothered), so
259  * it's a macro which always returns NULL. With any luck this will
260  * cause the compiler to notice it can optimise away the
261  * implementation of XDM-AUTHORIZATION-1 in x11fwd.c :-)
262  */
263 #define sk_getxdmdata(socket, lenp) (NULL)
264 
265 /*
266  * File-selector filter strings used in the config box. On Windows,
267  * these strings are of exactly the type needed to go in
268  * `lpstrFilter' in an OPENFILENAME structure.
269  */
270 #define FILTER_KEY_FILES ("PuTTY Private Key Files (*.ppk)\0*.ppk\0" \
271                               "All Files (*.*)\0*\0\0\0")
272 #define FILTER_WAVE_FILES ("Wave Files (*.wav)\0*.WAV\0" \
273                                "All Files (*.*)\0*\0\0\0")
274 #define FILTER_DYNLIB_FILES ("Dynamic Library Files (*.dll)\0*.dll\0" \
275                                  "All Files (*.*)\0*\0\0\0")
276 
277 /*
278  * Exports from winnet.c.
279  */
280 /* Report an event notification from WSA*Select */
281 void select_result(WPARAM, LPARAM);
282 /* Enumerate all currently live OS-level SOCKETs */
283 SOCKET first_socket(int *);
284 SOCKET next_socket(int *);
285 /* Ask winnet.c whether we currently want to try to write to a SOCKET */
286 bool socket_writable(SOCKET skt);
287 /* Force a refresh of the SOCKET list by re-calling do_select for each one */
288 void socket_reselect_all(void);
289 /* Make a SockAddr which just holds a named pipe address. */
290 SockAddr *sk_namedpipe_addr(const char *pipename);
291 /* Turn a WinSock error code into a string. */
292 const char *winsock_error_string(int error);
293 
294 /*
295  * winnet.c dynamically loads WinSock 2 or WinSock 1 depending on
296  * what it can get, which means any WinSock routines used outside
297  * that module must be exported from it as function pointers. So
298  * here they are.
299  */
300 DECL_WINDOWS_FUNCTION(extern, int, WSAAsyncSelect,
301                       (SOCKET, HWND, u_int, long));
302 DECL_WINDOWS_FUNCTION(extern, int, WSAEventSelect,
303                       (SOCKET, WSAEVENT, long));
304 DECL_WINDOWS_FUNCTION(extern, int, WSAGetLastError, (void));
305 DECL_WINDOWS_FUNCTION(extern, int, WSAEnumNetworkEvents,
306                       (SOCKET, WSAEVENT, LPWSANETWORKEVENTS));
307 #ifdef NEED_DECLARATION_OF_SELECT
308 /* This declaration is protected by an ifdef for the sake of building
309  * against winelib, in which you have to include winsock2.h before
310  * stdlib.h so that the right fd_set type gets defined. It would be a
311  * pain to do that throughout this codebase, so instead I arrange that
312  * only a modules actually needing to use (or define, or initialise)
313  * this function pointer will see its declaration, and _those_ modules
314  * - which will be Windows-specific anyway - can take more care. */
315 DECL_WINDOWS_FUNCTION(extern, int, select,
316                       (int, fd_set FAR *, fd_set FAR *,
317                        fd_set FAR *, const struct timeval FAR *));
318 #endif
319 
320 /*
321  * Implemented differently depending on the client of winnet.c, and
322  * called by winnet.c to turn on or off WSA*Select for a given socket.
323  */
324 const char *do_select(SOCKET skt, bool enable);
325 
326 /*
327  * Exports from winselgui.c and winselcli.c, each of which provides an
328  * implementation of do_select.
329  */
330 void winselgui_set_hwnd(HWND hwnd);
331 void winselgui_clear_hwnd(void);
332 
333 void winselcli_setup(void);
334 SOCKET winselcli_unique_socket(void);
335 extern HANDLE winselcli_event;
336 
337 /*
338  * Network-subsystem-related functions provided in other Windows modules.
339  */
340 Socket *make_handle_socket(HANDLE send_H, HANDLE recv_H, HANDLE stderr_H,
341                            Plug *plug, bool overlapped); /* winhsock */
342 Socket *new_named_pipe_client(const char *pipename, Plug *plug); /* winnpc */
343 Socket *new_named_pipe_listener(const char *pipename, Plug *plug); /* winnps */
344 
345 /* A lower-level function in winnpc.c, which does most of the work of
346  * new_named_pipe_client (including checking the ownership of what
347  * it's connected to), but returns a plain HANDLE instead of wrapping
348  * it into a Socket. */
349 HANDLE connect_to_named_pipe(const char *pipename, char **err);
350 
351 /*
352  * Exports from winctrls.c.
353  */
354 
355 struct ctlpos {
356     HWND hwnd;
357     WPARAM font;
358     int dlu4inpix;
359     int ypos, width;
360     int xoff;
361     int boxystart, boxid;
362     char *boxtext;
363 };
364 void init_common_controls(void);       /* also does some DLL-loading */
365 
366 /*
367  * Exports from winutils.c.
368  */
369 typedef struct filereq_tag filereq; /* cwd for file requester */
370 bool request_file(filereq *state, OPENFILENAME *of, bool preserve, bool save);
371 filereq *filereq_new(void);
372 void filereq_free(filereq *state);
373 void pgp_fingerprints_msgbox(HWND owner);
374 int message_box(HWND owner, LPCTSTR text, LPCTSTR caption,
375                 DWORD style, DWORD helpctxid);
376 void MakeDlgItemBorderless(HWND parent, int id);
377 char *GetDlgItemText_alloc(HWND hwnd, int id);
378 void split_into_argv(char *, int *, char ***, char ***);
379 
380 /*
381  * Private structure for prefslist state. Only in the header file
382  * so that we can delegate allocation to callers.
383  */
384 struct prefslist {
385     int listid, upbid, dnbid;
386     int srcitem;
387     int dummyitem;
388     bool dragging;
389 };
390 
391 /*
392  * This structure is passed to event handler functions as the `dlg'
393  * parameter, and hence is passed back to winctrls access functions.
394  */
395 struct dlgparam {
396     HWND hwnd;                         /* the hwnd of the dialog box */
397     struct winctrls *controltrees[8];  /* can have several of these */
398     int nctrltrees;
399     char *wintitle;                    /* title of actual window */
400     char *errtitle;                    /* title of error sub-messageboxes */
401     void *data;                        /* data to pass in refresh events */
402     union control *focused, *lastfocused; /* which ctrl has focus now/before */
403     bool shortcuts[128];               /* track which shortcuts in use */
404     bool coloursel_wanted;             /* has an event handler asked for
405                                         * a colour selector? */
406     struct {
407         unsigned char r, g, b;         /* 0-255 */
408         bool ok;
409     } coloursel_result;
410     tree234 *privdata;                 /* stores per-control private data */
411     bool ended;                        /* has the dialog been ended? */
412     int endresult;                     /* and if so, what was the result? */
413     bool fixed_pitch_fonts;            /* are we constrained to fixed fonts? */
414 };
415 
416 /*
417  * Exports from winctrls.c.
418  */
419 void ctlposinit(struct ctlpos *cp, HWND hwnd,
420                 int leftborder, int rightborder, int topborder);
421 HWND doctl(struct ctlpos *cp, RECT r,
422            char *wclass, int wstyle, int exstyle, char *wtext, int wid);
423 void bartitle(struct ctlpos *cp, char *name, int id);
424 void beginbox(struct ctlpos *cp, char *name, int idbox);
425 void endbox(struct ctlpos *cp);
426 void editboxfw(struct ctlpos *cp, bool password, char *text,
427                int staticid, int editid);
428 void radioline(struct ctlpos *cp, char *text, int id, int nacross, ...);
429 void bareradioline(struct ctlpos *cp, int nacross, ...);
430 void radiobig(struct ctlpos *cp, char *text, int id, ...);
431 void checkbox(struct ctlpos *cp, char *text, int id);
432 void statictext(struct ctlpos *cp, char *text, int lines, int id);
433 void staticbtn(struct ctlpos *cp, char *stext, int sid,
434                char *btext, int bid);
435 void static2btn(struct ctlpos *cp, char *stext, int sid,
436                 char *btext1, int bid1, char *btext2, int bid2);
437 void staticedit(struct ctlpos *cp, char *stext,
438                 int sid, int eid, int percentedit);
439 void staticddl(struct ctlpos *cp, char *stext,
440                int sid, int lid, int percentlist);
441 void combobox(struct ctlpos *cp, char *text, int staticid, int listid);
442 void staticpassedit(struct ctlpos *cp, char *stext,
443                     int sid, int eid, int percentedit);
444 void bigeditctrl(struct ctlpos *cp, char *stext,
445                  int sid, int eid, int lines);
446 void ersatztab(struct ctlpos *cp, char *stext, int sid, int lid, int s2id);
447 void editbutton(struct ctlpos *cp, char *stext, int sid,
448                 int eid, char *btext, int bid);
449 void sesssaver(struct ctlpos *cp, char *text,
450                int staticid, int editid, int listid, ...);
451 void envsetter(struct ctlpos *cp, char *stext, int sid,
452                char *e1stext, int e1sid, int e1id,
453                char *e2stext, int e2sid, int e2id,
454                int listid, char *b1text, int b1id, char *b2text, int b2id);
455 void charclass(struct ctlpos *cp, char *stext, int sid, int listid,
456                char *btext, int bid, int eid, char *s2text, int s2id);
457 void colouredit(struct ctlpos *cp, char *stext, int sid, int listid,
458                 char *btext, int bid, ...);
459 void prefslist(struct prefslist *hdl, struct ctlpos *cp, int lines,
460                char *stext, int sid, int listid, int upbid, int dnbid);
461 int handle_prefslist(struct prefslist *hdl,
462                      int *array, int maxmemb,
463                      bool is_dlmsg, HWND hwnd,
464                      WPARAM wParam, LPARAM lParam);
465 void progressbar(struct ctlpos *cp, int id);
466 void fwdsetter(struct ctlpos *cp, int listid, char *stext, int sid,
467                char *e1stext, int e1sid, int e1id,
468                char *e2stext, int e2sid, int e2id,
469                char *btext, int bid,
470                char *r1text, int r1id, char *r2text, int r2id);
471 
472 void dlg_auto_set_fixed_pitch_flag(dlgparam *dlg);
473 bool dlg_get_fixed_pitch_flag(dlgparam *dlg);
474 void dlg_set_fixed_pitch_flag(dlgparam *dlg, bool flag);
475 
476 #define MAX_SHORTCUTS_PER_CTRL 16
477 
478 /*
479  * This structure is what's stored for each `union control' in the
480  * portable-dialog interface.
481  */
482 struct winctrl {
483     union control *ctrl;
484     /*
485      * The control may have several components at the Windows
486      * level, with different dialog IDs. To avoid needing N
487      * separate platformsidectrl structures (which could be stored
488      * separately in a tree234 so that lookup by ID worked), we
489      * impose the constraint that those IDs must be in a contiguous
490      * block.
491      */
492     int base_id;
493     int num_ids;
494     /*
495      * For vertical alignment, the id of a particular representative
496      * control that has the y-extent of the sensible part of the
497      * control.
498      */
499     int align_id;
500     /*
501      * Remember what keyboard shortcuts were used by this control,
502      * so that when we remove it again we can take them out of the
503      * list in the dlgparam.
504      */
505     char shortcuts[MAX_SHORTCUTS_PER_CTRL];
506     /*
507      * Some controls need a piece of allocated memory in which to
508      * store temporary data about the control.
509      */
510     void *data;
511 };
512 /*
513  * And this structure holds a set of the above, in two separate
514  * tree234s so that it can find an item by `union control' or by
515  * dialog ID.
516  */
517 struct winctrls {
518     tree234 *byctrl, *byid;
519 };
520 struct controlset;
521 struct controlbox;
522 
523 void winctrl_init(struct winctrls *);
524 void winctrl_cleanup(struct winctrls *);
525 void winctrl_add(struct winctrls *, struct winctrl *);
526 void winctrl_remove(struct winctrls *, struct winctrl *);
527 struct winctrl *winctrl_findbyctrl(struct winctrls *, union control *);
528 struct winctrl *winctrl_findbyid(struct winctrls *, int);
529 struct winctrl *winctrl_findbyindex(struct winctrls *, int);
530 void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
531                     struct ctlpos *cp, struct controlset *s, int *id);
532 bool winctrl_handle_command(struct dlgparam *dp, UINT msg,
533                             WPARAM wParam, LPARAM lParam);
534 void winctrl_rem_shortcuts(struct dlgparam *dp, struct winctrl *c);
535 bool winctrl_context_help(struct dlgparam *dp, HWND hwnd, int id);
536 
537 void dp_init(struct dlgparam *dp);
538 void dp_add_tree(struct dlgparam *dp, struct winctrls *tree);
539 void dp_cleanup(struct dlgparam *dp);
540 
541 /*
542  * Exports from wincfg.c.
543  */
544 void win_setup_config_box(struct controlbox *b, HWND *hwndp, bool has_help,
545                           bool midsession, int protocol);
546 
547 /*
548  * Exports from windlg.c.
549  */
550 void defuse_showwindow(void);
551 bool do_config(Conf *);
552 bool do_reconfig(HWND, Conf *, int);
553 void showeventlog(HWND);
554 void showabout(HWND);
555 void force_normal(HWND hwnd);
556 void modal_about_box(HWND hwnd);
557 void show_help(HWND hwnd);
558 HWND event_log_window(void);
559 
560 /*
561  * Exports from winmisc.c.
562  */
563 extern DWORD osMajorVersion, osMinorVersion, osPlatformId;
564 void init_winver(void);
565 void dll_hijacking_protection(void);
566 HMODULE load_system32_dll(const char *libname);
567 const char *win_strerror(int error);
568 void restrict_process_acl(void);
569 bool restricted_acl(void);
570 void escape_registry_key(const char *in, strbuf *out);
571 void unescape_registry_key(const char *in, strbuf *out);
572 
573 bool is_console_handle(HANDLE);
574 
575 /* A few pieces of up-to-date Windows API definition needed for older
576  * compilers. */
577 #ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
578 #define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
579 #endif
580 #ifndef LOAD_LIBRARY_SEARCH_USER_DIRS
581 #define LOAD_LIBRARY_SEARCH_USER_DIRS 0x00000400
582 #endif
583 #ifndef LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
584 #define LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR 0x00000100
585 #endif
586 #ifndef DLL_DIRECTORY_COOKIE
587 typedef PVOID DLL_DIRECTORY_COOKIE;
588 DECLSPEC_IMPORT DLL_DIRECTORY_COOKIE WINAPI AddDllDirectory (PCWSTR NewDirectory);
589 #endif
590 
591 /*
592  * Exports from sizetip.c.
593  */
594 void UpdateSizeTip(HWND src, int cx, int cy);
595 void EnableSizeTip(bool bEnable);
596 
597 /*
598  * Exports from unicode.c.
599  */
600 struct unicode_data;
601 void init_ucs(Conf *, struct unicode_data *);
602 
603 /*
604  * Exports from winhandl.c.
605  */
606 #define HANDLE_FLAG_OVERLAPPED 1
607 #define HANDLE_FLAG_IGNOREEOF 2
608 #define HANDLE_FLAG_UNITBUFFER 4
609 struct handle;
610 typedef size_t (*handle_inputfn_t)(
611     struct handle *h, const void *data, size_t len, int err);
612 typedef void (*handle_outputfn_t)(
613     struct handle *h, size_t new_backlog, int err);
614 struct handle *handle_input_new(HANDLE handle, handle_inputfn_t gotdata,
615                                 void *privdata, int flags);
616 struct handle *handle_output_new(HANDLE handle, handle_outputfn_t sentdata,
617                                  void *privdata, int flags);
618 size_t handle_write(struct handle *h, const void *data, size_t len);
619 void handle_write_eof(struct handle *h);
620 HANDLE *handle_get_events(int *nevents);
621 void handle_free(struct handle *h);
622 void handle_got_event(HANDLE event);
623 void handle_unthrottle(struct handle *h, size_t backlog);
624 size_t handle_backlog(struct handle *h);
625 void *handle_get_privdata(struct handle *h);
626 struct handle *handle_add_foreign_event(HANDLE event,
627                                         void (*callback)(void *), void *ctx);
628 /* Analogue of stdio_sink in marshal.h, for a Windows handle */
629 struct handle_sink {
630     struct handle *h;
631     BinarySink_IMPLEMENTATION;
632 };
633 void handle_sink_init(handle_sink *sink, struct handle *h);
634 
635 /*
636  * Exports from winpgntc.c.
637  */
638 char *agent_named_pipe_name(void);
639 
640 /*
641  * Exports from winser.c.
642  */
643 extern const struct BackendVtable serial_backend;
644 
645 /*
646  * Exports from winjump.c.
647  */
648 #define JUMPLIST_SUPPORTED             /* suppress #defines in putty.h */
649 void add_session_to_jumplist(const char * const sessionname);
650 void remove_session_from_jumplist(const char * const sessionname);
651 void clear_jumplist(void);
652 bool set_explicit_app_user_model_id(void);
653 
654 /*
655  * Exports from winnoise.c.
656  */
657 bool win_read_random(void *buf, unsigned wanted); /* returns true on success */
658 
659 /*
660  * Extra functions in winstore.c over and above the interface in
661  * storage.h.
662  *
663  * These functions manipulate the Registry section which mirrors the
664  * current Windows 7 jump list. (Because the real jump list storage is
665  * write-only, we need to keep another copy of whatever we put in it,
666  * so that we can put in a slightly modified version the next time.)
667  */
668 
669 /* Adds a saved session to the registry jump list mirror. 'item' is a
670  * string naming a saved session. */
671 int add_to_jumplist_registry(const char *item);
672 
673 /* Removes an item from the registry jump list mirror. */
674 int remove_from_jumplist_registry(const char *item);
675 
676 /* Returns the current jump list entries from the registry. Caller
677  * must free the returned pointer, which points to a contiguous
678  * sequence of NUL-terminated strings in memory, terminated with an
679  * empty one. */
680 char *get_jumplist_registry_entries(void);
681 
682 /*
683  * Windows clipboard-UI wording.
684  */
685 #define CLIPNAME_IMPLICIT "Last selected text"
686 #define CLIPNAME_EXPLICIT "System clipboard"
687 #define CLIPNAME_EXPLICIT_OBJECT "system clipboard"
688 /* These defaults are the ones PuTTY has historically had */
689 #define CLIPUI_DEFAULT_AUTOCOPY true
690 #define CLIPUI_DEFAULT_MOUSE CLIPUI_EXPLICIT
691 #define CLIPUI_DEFAULT_INS CLIPUI_EXPLICIT
692 
693 /* In winmisc.c */
694 char *registry_get_string(HKEY root, const char *path, const char *leaf);
695 
696 /* In wincliloop.c */
697 typedef bool (*cliloop_pre_t)(void *vctx, const HANDLE **extra_handles,
698                               size_t *n_extra_handles);
699 typedef bool (*cliloop_post_t)(void *vctx, size_t extra_handle_index);
700 void cli_main_loop(cliloop_pre_t pre, cliloop_post_t post, void *ctx);
701 bool cliloop_null_pre(void *vctx, const HANDLE **, size_t *);
702 bool cliloop_null_post(void *vctx, size_t);
703 
704 #endif
705