home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / winsock / globchat / client / globals.h < prev    next >
C/C++ Source or Header  |  1997-10-05  |  12KB  |  340 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1997  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. // PURPOSE:
  9. //    Contains declarations for all globally scoped names in the program.
  10. //
  11.  
  12. //-------------------------------------------------------------------------
  13. // Product identifier string defines
  14.  
  15. #define APPNAME       GlobCl
  16.  
  17.  
  18. //-------------------------------------------------------------------------
  19. // Functions for handling main window messages.  The message-dispatching
  20. // mechanism expects all message-handling functions to have the following
  21. // prototype:
  22. //
  23. //     LRESULT FunctionName(HWND, UINT, WPARAM, LPARAM);
  24.  
  25. LRESULT MsgCreate(HWND, UINT, WPARAM, LPARAM);
  26. LRESULT MsgSize(HWND, UINT, WPARAM, LPARAM);
  27. LRESULT MsgSetfocus(HWND, UINT, WPARAM, LPARAM);
  28. LRESULT MsgCommand(HWND, UINT, WPARAM, LPARAM);
  29. LRESULT MsgDataready(HWND, UINT, WPARAM, LPARAM);
  30. LRESULT MsgRefreshdisplay(HWND, UINT, WPARAM, LPARAM);
  31. LRESULT MsgDisconnected(HWND, UINT, WPARAM, LPARAM);
  32. LRESULT MsgDestroy(HWND, UINT, WPARAM, LPARAM);
  33.  
  34.  
  35. //-------------------------------------------------------------------------
  36. // Functions for handling main window commands--ie. functions for
  37. // processing WM_COMMAND messages based on the wParam value.
  38. // The message-dispatching mechanism expects all command-handling
  39. // functions to have the following prototype:
  40. //
  41. //     LRESULT FunctionName(HWND, WORD, WORD, HWND);
  42.  
  43. LRESULT CmdConnect(HWND, WORD, WORD, HWND);
  44. LRESULT CmdSelect(HWND, WORD, WORD, HWND);
  45. LRESULT CmdExit(HWND, WORD, WORD, HWND);
  46. LRESULT CmdAbout(HWND, WORD, WORD, HWND);
  47. LRESULT CmdOutbox(HWND, WORD, WORD, HWND);
  48. LRESULT CmdDisconnect(HWND, WORD, WORD, HWND);
  49. LRESULT CmdEndChat(HWND, WORD, WORD, HWND);
  50.  
  51. //
  52. //   Socket Data transfer Message definitions
  53. //
  54. typedef struct _MSGHDR            // Message Header
  55. {
  56.     BYTE            signature;    // Identifies start of a message
  57.     WORD            length;       // size of message
  58.     BYTE            command;      // message command
  59. } MSGHDR, *LPMSGHDR;
  60.  
  61.  
  62. typedef struct _DATAMSG            // Message--contains header + data
  63. {
  64.     MSGHDR          hdr;
  65.     BYTE            data[0x8000];  // data
  66. } DATAMSG, *LPDATAMSG;
  67.  
  68. DATAMSG xferbuf;
  69.  
  70.  
  71. // Message constants
  72. #define HDRSIZE      sizeof(MSGHDR)    // Size of Message header
  73. #define REALLEN(x)   lstrlen(x) + 1    // REALLEN will now count terminating NULL of x
  74.  
  75. //    Globchat socket data structure to hold all necessary socket information
  76. //
  77. typedef struct _SOCKDATA
  78. {
  79.     SOCKET           sock;         // socket handle
  80.     int              status;       // Socket's status
  81.     struct sockaddr  addr;         // Address structure
  82.     char             reserved[10]; // Generic sockaddr struct is not big enough for all
  83.                                    // addresses (namely netbios addresses) so adding some
  84.                                    // space at the end.
  85.     int              addrlen;      // Address length
  86.     int              type;         // Socket type (from socket() call)
  87.     int              protocol;     // protocol (from socket() call)
  88.     int              currconnects; // Number of current connections on this socket
  89.     SOCKET           peer;         // Handle of server's peer socket we are connected to
  90.     char             name[16];      // Our name
  91. } SOCKDATA, *LPSOCKDATA;
  92.  
  93. SOCKDATA MySock;
  94.  
  95. //  SOCKDATA structure status options
  96. #define SOCKSTAT_INIT        1
  97. #define SOCKSTAT_LISTENING   2
  98. #define SOCKSTAT_ACCEPTING   3
  99. #define SOCKSTAT_CLOSED      4
  100. #define SOCKSTAT_CONNECTED   5
  101. #define SOCKSTAT_AVAILABLE   6
  102. #define SOCKSTAT_INSESSION   7
  103. #define SOCKSTAT_REQSESSION  8
  104.  
  105. //-------------------------------------------------------------------------
  106. // Global function prototypes.
  107.  
  108. BOOL InitApplication(HINSTANCE, int);
  109. BOOL CenterWindow(HWND, HWND);
  110. BOOL ReceiveInBox(HWND, WPARAM, LPARAM, char *, int);
  111. void SendOutBox(char *, int);
  112. void AtoH(char *, char *, int);
  113. unsigned char BtoH(char);
  114. void CleanUp(void);
  115. void GetAddrString(PSOCKADDR_IPX, char *);
  116. void HtoA(char *, char *, int);
  117. char HtoB(UCHAR);
  118. BOOL senddatamessage (SOCKET, LPDATAMSG);
  119. BOOL recvdatamessage (LPSOCKDATA, LPDATAMSG);
  120. LPTSTR GetStringRes (int id);
  121.  
  122.  
  123.  
  124. // Callback functions.  These are called by Windows.
  125.  
  126. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  127.  
  128.  
  129. //-------------------------------------------------------------------------
  130. // Command ID definitions.  These definitions are used to associate menu
  131. // items with commands.
  132.  
  133. // Options menu
  134. #define IDM_CONNECT           1000
  135. #define IDM_SELECT            1001
  136. #define IDM_END_CHAT          1002
  137. #define IDM_DISCONNECT_SERVER 1003
  138. #define IDM_EXIT              1004
  139.  
  140. // Help menu
  141. #define IDM_ABOUT      1100
  142.  
  143. //-------------------------------------------------------------------------
  144. // User Defined Messages.  These definitions are used for indicating
  145. // network events.
  146.  
  147. #define MW_DATAREADY       501
  148. #define MW_DISPLAYREFRESH  502
  149. #define MW_DISCONNECTED    503
  150. #define LDM_CONNECTED      504
  151.  
  152. //-------------------------------------------------------------------------
  153. // String Table ID definitions.
  154.  
  155. #define IDS_APPNAME                       1
  156. #define IDS_DESCRIPTION                   2
  157. #define IDS_FILEINFOLANG                  3
  158. #define IDS_CHAT_AVAIL                    4
  159. #define IDS_ERR_SERVER_NOT_FOUND          5
  160. #define IDS_ERR_NAMESPACE_NOT_SUPPORTED   6
  161. #define IDS_ERR_SOCKET_FAILED             7
  162. #define IDS_ERR_CONNECT_FAILED            8
  163. #define IDS_ERR_WSAASYNCSELECT            9
  164. #define IDS_ERR_UNSUPPORTED_PROTOCOL      10
  165. #define IDS_ERR_CONNECTION_DROPPED        11
  166. #define IDS_CALLING_SOCKET                12
  167. #define IDS_CALLING_CONNECT               13
  168. #define IDS_WAITING_FOR_ACCEPT            14
  169. #define IDS_SELECT_PROTOCOL               15
  170. #define IDS_ENTER_NAME                    16
  171. #define IDS_ENTER_MACHINE_NAME            17
  172. #define IDS_CONNECTION_STOPPED            18
  173. #define IDS_CHAT_DLG_STOPPED              19
  174. #define IDS_CHAT_AVAILABLE                20
  175. #define IDS_CHATTING_REMOTE               21
  176. #define IDS_REQUESTS_CHAT                 22
  177. #define IDS_SESSION_REQUEST               23
  178.  
  179.  
  180. //-------------------------------------------------------------------------
  181. //  Main Window Edit Control defines.
  182.  
  183. #define ID_OUTBOX          601
  184. #define ID_INBOX           602
  185.  
  186. //-------------------------------------------------------------------------
  187. //  About dialog defines.
  188.  
  189. #define IDD_VERFIRST    100
  190. #define IDD_VERLAST     104
  191.  
  192. //-------------------------------------------------------------------------
  193. //  Connect dialog defines.
  194.  
  195. #define CD_NAME        200
  196. #define CD_PROTOCOL    201
  197. #define CD_SERVER      202
  198. #define CD_SERVER_TEXT 203
  199. #define CD_HELP        204
  200.  
  201. //-------------------------------------------------------------------------
  202. //  Select dialog defines.
  203.  
  204. #define SD_LIST        300
  205.  
  206. //-------------------------------------------------------------------------
  207. //  Globchat socket message commands
  208.  
  209. #define REGISTER_NAME             1
  210. #define XFER_DATA                 2
  211. #define REQUEST_SESSION           3
  212. #define SESSION_REQUEST_RESPONSE  4
  213. #define SESSION_CLOSE             5
  214. #define DEREGISTER_NAME           6
  215.  
  216. //-------------------------------------------------------------------------
  217. //  Socket constants
  218. #define MYSIGNATURE               0xCC        // Starts every globchat socket message header
  219. #define NWCHATID                  0x0756      // 0x0756 (network order) was assigned by Novell
  220.                                               // for this specific application
  221. #define DNSCHATID                 0x555       // Well known socket for DNS GUID generation
  222.  
  223.  
  224. //-------------------------------------------------------------------------
  225. // Global variable declarations.
  226.  
  227. extern HINSTANCE hInst;          // The current instance handle
  228. extern char      szAppName[];    // The name of this application
  229. extern char      szTitle[];      // The title bar text
  230. SOCKET sock, SrvSock;
  231. SOCKADDR_IPX RemAddr;
  232. PSOCKADDR_IPX pSockAddr, pRemAddr;
  233. struct sockaddr addr;
  234. int addrlen;
  235. HWND hOutWnd, hInWnd;
  236. char szRcvBuf[0x8000];
  237. char szSndBuf[0x8000];
  238. extern char szConnectName[];
  239. extern char szConnectServer[];
  240. CSADDR_INFO CSAInfo[10];
  241. CSADDR_INFO CSABuf[20];
  242. DWORD dwCSABufsize;
  243. char peername[16];
  244. LPPROTOCOL_INFO lpProtBuf;
  245. int goodprots[30];
  246. char lpServName[256];
  247. SOCKADDR_NB NBAddr;
  248. SOCKADDR_IPX IPXAddr;
  249.  
  250.  
  251. #define hwndMDIGlobCl NULL        /* Stub for NON-MDI applications. */
  252.  
  253.  
  254. //-------------------------------------------------------------------------
  255. // Message and command dispatch infrastructure.  The following type
  256. // definitions and functions are used by the message and command dispatching
  257. // mechanism and do not need to be changed.
  258.  
  259.     // Function pointer prototype for message handling functions.
  260. typedef LRESULT (*PFNMSG)(HWND,UINT,WPARAM,LPARAM);
  261.  
  262.     // Function pointer prototype for command handling functions.
  263. typedef LRESULT (*PFNCMD)(HWND,WORD,WORD,HWND);
  264.  
  265.     // Enumerated type used to determine which default window procedure
  266.     // should be called by the message- and command-dispatching mechanism
  267.     // if a message or command is not handled explicitly.
  268. typedef enum
  269. {
  270.    edwpNone,            // Do not call any default procedure.
  271.    edwpWindow,          // Call DefWindowProc.
  272.    edwpDialog,          // Call DefDlgProc (This should be used only for
  273.                         // custom dialogs - standard dialog use edwpNone).
  274.    edwpMDIChild,        // Call DefMDIChildProc.
  275.    edwpMDIFrame         // Call DefFrameProc.
  276. } EDWP;                // Enumeration for Default Window Procedures
  277.  
  278.     // This structure maps messages to message handling functions.
  279. typedef struct _MSD
  280. {
  281.     UINT   uMessage;
  282.     PFNMSG pfnmsg;
  283. } MSD;                 // MeSsage Dispatch structure
  284.  
  285.     // This structure contains all of the information that a window
  286.     // procedure passes to DispMessage in order to define the message
  287.     // dispatching behavior for the window.
  288. typedef struct _MSDI
  289. {
  290.     int  cmsd;          // Number of message dispatch structs in rgmsd
  291.     MSD *rgmsd;         // Table of message dispatch structures
  292.     EDWP edwp;          // Type of default window handler needed.
  293. } MSDI, FAR *LPMSDI;   // MeSsage Dipatch Information
  294.  
  295.     // This structure maps command IDs to command handling functions.
  296. typedef struct _CMD
  297. {
  298.     WORD   wCommand;
  299.     PFNCMD pfncmd;
  300. } CMD;                 // CoMmand Dispatch structure
  301.  
  302.     // This structure contains all of the information that a command
  303.     // message procedure passes to DispCommand in order to define the
  304.     // command dispatching behavior for the window.
  305. typedef struct _CMDI
  306. {
  307.     int  ccmd;          // Number of command dispatch structs in rgcmd
  308.     CMD *rgcmd;         // Table of command dispatch structures
  309.     EDWP edwp;          // Type of default window handler needed.
  310. } CMDI, FAR *LPCMDI;   // CoMmand Dispatch Information
  311.  
  312.     // Message and command dispatching functions.  They look up messages
  313.     // and commands in the dispatch tables and call the appropriate handler
  314.     // function.
  315. LRESULT DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM);
  316. LRESULT DispCommand(LPCMDI, HWND, WPARAM, LPARAM);
  317.  
  318.     // Message dispatch information for the main window
  319. extern MSDI msdiMain;
  320.     // Command dispatch information for the main window
  321. extern CMDI cmdiMain;
  322.  
  323.  
  324.  
  325. //-------------------------------------------------------------------------
  326. // Version string definitions--Leave these alone.
  327.  
  328. #define SZRCOMPANYNAME "CompanyName"
  329. #define SZRDESCRIPTION "FileDescription"
  330. #define SZRVERSION     "FileVersion"
  331. #define SZRAPPNAME     "InternalName"
  332. #define SZRCOPYRIGHT   "LegalCopyright"
  333. #define SZRTRADEMARK   "LegalTrademarks"
  334. #define SZRPRODNAME    "ProductName"
  335. #define SZRPRODVER     "ProuctVersion"
  336.  
  337.  
  338.  
  339.  
  340.