/* EvryThng.h -- All standard and custom include files. */ #include "Exclude.h" /* Excludes definitions not required by sample programs. */ #include "envirmnt.h" #include <windows.h> #include <tchar.h> #include <stdio.h> #include <io.h> #include "support.h" #ifdef _MT #include <process.h> /* DWORD_PTR (pointer precision unsigned integer) is used for integers * that are converted to handles or pointers. * This eliminates Win64 warnings regarding conversion between * 32-bit and 64-bit data, as HANDLEs and pointers are 64 bits in * Win64 (see Chapter 16). This is enabled only if _Wp64 is defined. */ #if !defined(_Wp64) #define DWORD_PTR DWORD #define LONG_PTR LONG #define INT_PTR INT #endif
/* Envirmnt.h -- define UNICODE and _MT here. */ /* It is best and easiest to define UNICODE within the project. */ /* Use Project...Settings...C/C++. Then, in the "Project Options" */ /* window on the bottom, add /D "UNICODE". */ /* Do the same for _MT, and _STATIC_LIB. */ //#define UNICODE #undef UNICODE #ifdef UNICODE #define _UNICODE #endif #ifndef UNICODE #undef _UNICODE #endif //#define _STATICLIB /* Define _STATICLIB if you are either building a */ /* static library or linking with one. */ #define LANG_DFLT LANG_ENGLISH #define SUBLANG_DFLT SUBLANG_ENGLISH_US
/* Support.h */ /* Definitions of all symbolic constants and common utility functions used throughout the example programs. */ /* IT IS BEST TO DEFINE UTILITY_EXPORTS AND _STATICLIB WITHIN THE PROJECT RATHER THAN HERE, BUT THE DESCRIPTIONS ARE INCLUDED. */ /* The name "UTILITY_EXPORTS" is generated by Dev Studio when you create a DLL project named "Utility" and it is defined on the C command line. */ // UTILITY_3_0_EXPORTS is defined within the UTILITY_3_0 project. #if defined(UTILITY_3_0_EXPORTS) #define LIBSPEC _declspec (dllexport) #elif defined(__cplusplus) #define LIBSPEC extern "C" _declspec (dllimport) #else #define LIBSPEC _declspec (dllimport) #endif #define EMPTY _T (") #define YES _T ("y") #define NO _T ("n") #define CR 0x0D #define LF 0x0A #define TSIZE sizeof (TCHAR) /* Limits and constants. */ #define TYPE_FILE 1 /* Used in ls, rm, and lsFP. */ #define TYPE_DIR 2 #define TYPE_DOT 3 #define MAX_OPTIONS 20 /* Max # of command line options. */ #define MAX_ARG 1000 /* Max # of command line arguments. */ #define MAX_COMMAND_LINE MAX_PATH+50 /* Max size of a command line. */ /* Commonly used functions. */ LIBSPEC BOOL ConsolePrompt (LPCTSTR, LPTSTR, DWORD, BOOL); LIBSPEC BOOL PrintStrings (HANDLE, ...); LIBSPEC BOOL PrintMsg (HANDLE, LPCTSTR); LIBSPEC VOID ReportError (LPCTSTR, DWORD, BOOL); LIBSPEC VOID ReportException (LPCTSTR, DWORD); LIBSPEC DWORD Options (int, LPCTSTR *, LPCTSTR, ...); LIBSPEC LPTSTR SkipArg (LPCTSTR); LIBSPEC VOID GetArgs (LPCTSTR, int *, LPTSTR *); /* Collection of generic string functions modeled after string.h. Created as required -- there was only one! Implementation is derived from Plauger: The Standard C Library. */ LIBSPEC LPCTSTR wmemchr (LPCTSTR, TCHAR, DWORD); #ifdef _UNICODE /* This declaration had to be added. */ #define _tstrrchr wcsrchr #else #define _tstrrchr strrchr #endif #ifdef _UNICODE /* This declaration had to be added. */ #define _memtchr wmemchr #else #define _memtchr memchr #endif /* Security functions. */ LPSECURITY_ATTRIBUTES InitializeUnixSA (DWORD, LPTSTR, LPTSTR, LPDWORD, LPHANDLE); LPSECURITY_ATTRIBUTES InitializeAccessOnlySA (DWORD, LPTSTR, LPTSTR, LPDWORD, LPHANDLE); DWORD ReadFilePermissions (LPTSTR, LPTSTR, LPTSTR); BOOL ChangeFilePermissions (DWORD, LPTSTR, LPDWORD, LPDWORD); /* Simpler forms available with Visual C++ Version 5.0. */ //PSECURITY_DESCRIPTOR InitializeSD (DWORD, LPTSTR, LPTSTR, LPDWORD); /* Constants needed by the security functions. */ #define LUSIZE 1024 #define ACCT_NAME_SIZE LUSIZE
/* JobMgt.h -- Definitions required for job management. Chapter 6. */ /* Job management exit code for killed jobs. */ #define JM_EXIT_CODE 0x1000 typedef struct _JM_JOB { DWORD ProcessId; TCHAR CommandLine [MAX_PATH]; } JM_JOB; #define SJM_JOB sizeof (JM_JOB) /* Job management functions. */ DWORD GetJobNumber (PROCESS_INFORMATION *, LPCTSTR); BOOL DisplayJobs (void); DWORD FindProcessId (DWORD); BOOL GetJobMgtFileName (LPTSTR);
/* Definitions for client/server communication. */ /* Request and response messages. Messages are in ASCII as the request may be coming from a Windows 95 system. */ #define MAX_RQRS_LEN 0x1000 typedef struct { DWORD32 RqLen; /* Request length, not including this field. */ CHAR Command; BYTE Record [MAX_RQRS_LEN]; } REQUEST; typedef struct { DWORD32 RsLen; /* Response length, not including this field */ CHAR Status; BYTE Record [MAX_RQRS_LEN]; } RESPONSE; #define RQ_SIZE sizeof (REQUEST) #define RQ_HEADER_LEN RQ_SIZE-MAX_RQRS_LEN #define RS_SIZE sizeof (RESPONSE) #define RS_HEADER_LEN RS_SIZE-MAX_RQRS_LEN /* Mailslot message structure. */ typedef struct { DWORD msStatus; DWORD msUtilization; TCHAR msName [MAX_PATH]; } MS_MESSAGE; #define MSM_SIZE sizeof (MS_MESSAGE) #define CS_TIMEOUT 5000 /* Time-out period for named pipe connections and performance monitoring. */ #define MAX_CLIENTS 10 #define MAX_SERVER_TH 4 /* Max num of server threads for serverNPCP.*/ #define MAX_CLIENTS_CP 16 /* Max num of clients for serverNPCP.*/ /* Client and server pipe & mailslot names. */ #define SERVER_PIPE _T ("\\\\.\\PIPE\\SERVER") #define CLIENT_PIPE _T ("\\\\.\\PIPE\\SERVER") #define SERVER_BROADCAST _T ("SrvrBcst.exe") #define MS_SRVNAME _T ("\\\\.\\MAILSLOT\\CLS_MAILSLOT") #define MS_CLTNAME _T ("\\\\.\\MAILSLOT\\CLS_MAILSLOT") #define MX_NAME _T ("ClientServerMutex") #define SM_NAME _T ("ClientServerSemaphore") /* Commands for the statistics maintenance function. */ #define CS_INIT 1 #define CS_RQSTART 2 #define CS_RQCOMPLETE 3 #define CS_REPORT 4 #define CS_TERMTHD 5 /* Client/Server support functions. */ BOOL LocateServer (LPTSTR);
Program A-6 defines numerous variables that will exclude definitions not required by the programs in the book. Rector and Newcomer (1997) discuss this in detail.
/* Exclude.h -- Define variables to exclude selected header files. For a complete explanation, see Rector & Newcomer, Win32 Programming, pp 25ff. */ #define WIN32_LEAN_AND_MEAN /* This has the largest impact, halving the precompiled header (pch) file size. */ /* These definitions also reduce the pch and improve compiling time. All the programs in the book will still compile with these definitions. You can also eliminate security with #define NOSECURITY. */ #define NOATOM #define NOCLIPBOARD #define NOCOMM #define NOCTLMGR #define NOCOLOR #define NODEFERWINDOWPOS #define NODESKTOP #define NODRAWTEXT #define NOEXTAPI #define NOGDICAPMASKS #define NOHELP #define NOICONS #define NOTIME #define NOIMM #define NOKANJI #define NOKERNEL #define NOKEYSTATES #define NOMCX #define NOMEMMGR #define NOMENUS #define NOMETAFILE #define NOMSG #define NONCMESSAGES #define NOPROFILER #define NORASTEROPS #define NORESOURCE #define NOSCROLL #define NOSERVICE #define NOSHOWWINDOW #define NOSOUND #define NOSYSCOMMANDS #define NOSYSMETRICS #define NOSYSPARAMS #define NOTEXTMETRIC #define NOVIRTUALKEYCODES #define NOWH #define NOWINDOWSTATION #define NOWINMESSAGES #define NOWINOFFSETS #define NOWINSTYLES #define OEMRESOURCE