Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
9.9 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: Srvrmain.c Server Main module
  3. *
  4. * Purpose: Includes server intialization and termination code.
  5. *
  6. * Created: Oct 1990.
  7. *
  8. * Copyright (c) 1990, 1991 Microsoft Corporation
  9. *
  10. * History:
  11. * Raor (../10/1990) Designed, coded
  12. *
  13. *
  14. \***************************************************************************/
  15. #include "cmacs.h"
  16. #include "windows.h"
  17. #include "ole.h"
  18. #include "dde.h"
  19. #include "srvr.h"
  20. #ifndef WF_WLO
  21. #define WF_WLO 0x8000
  22. #endif
  23. // ordinal number of new Win31 API IsTask
  24. #define ORD_IsTask 320
  25. // ordinal number of new Win31 API SetMetaFileBitsBetter
  26. #define ORD_SetMetaFileBitsBetter 196
  27. #ifdef FIREWALLS
  28. short ole_flags;
  29. char szDebugBuffer[80];
  30. void SetOleFlags(void);
  31. #endif
  32. // public vars.
  33. // atomes used in the systems
  34. ATOM aStdExit; // "StdExit"
  35. ATOM aStdCreate; // "StdNewDicument"
  36. ATOM aStdOpen; // "StdOpenDocument"
  37. ATOM aStdEdit; // "StdOpenDocument"
  38. ATOM aStdCreateFromTemplate; // "StdNewFromTemplate"
  39. ATOM aStdClose; // "StdCloseDocument"
  40. ATOM aStdShowItem; // "StdShowItem"
  41. ATOM aStdDoVerbItem; // "StddoVerbItem"
  42. ATOM aSysTopic; // "System"
  43. ATOM aOLE; // "OLE"
  44. ATOM aStdDocName; // "StdDocumentName"
  45. ATOM cfBinary; // "Binary format"
  46. ATOM cfNative; // "NativeFormat"
  47. ATOM cfLink; // "ObjectLink"
  48. ATOM cfOwnerLink; // "Ownerlink"
  49. ATOM aChange; // "Change"
  50. ATOM aSave; // "Save"
  51. ATOM aClose; // "Close"
  52. ATOM aProtocols; // "Protocols"
  53. ATOM aTopics; // "Topics"
  54. ATOM aFormats; // "Formats"
  55. ATOM aStatus; // "Status"
  56. ATOM aEditItems; // "Edit items
  57. ATOM aTrue; // "True"
  58. ATOM aFalse; // "False"
  59. // !!! free the proc instances.
  60. FARPROC lpSendRenameMsg; // Call back enum props for rename
  61. FARPROC lpSendDataMsg; // Call back enum props for data
  62. FARPROC lpFindItemWnd; // Callback in enum props of
  63. FARPROC lpItemCallBack; // CallBack for object
  64. FARPROC lpTerminateClients; // Callback in Doc enum properties
  65. FARPROC lpTerminateDocClients; // Callback in Doc enum properties
  66. FARPROC lpDeleteClientInfo; // proc for deleteing each item client
  67. FARPROC lpEnumForTerminate; // proc for terminating clients not in rename list
  68. FARPROC lpfnSetMetaFileBitsBetter = NULL;
  69. FARPROC lpfnIsTask = NULL;
  70. HANDLE hdllInst;
  71. BOOL bProtMode;
  72. BOOL bWLO = FALSE;
  73. BOOL bWin30 = FALSE;
  74. VOID FAR PASCAL WEP (int);
  75. #pragma alloc_text(WEP_TEXT, WEP)
  76. int FAR PASCAL LibMain (hInst, wDataSeg, cbHeapSize, lpszCmdLine)
  77. HANDLE hInst;
  78. WORD wDataSeg;
  79. WORD cbHeapSize;
  80. LPSTR lpszCmdLine;
  81. {
  82. WNDCLASS wc;
  83. Puts("LibMain");
  84. #ifdef FIREWALLS
  85. SetOleFlags();
  86. #endif
  87. hdllInst = hInst;
  88. bProtMode = (BOOL) (GetWinFlags() & WF_PMODE & 0x0000FFFF);
  89. bWLO = (BOOL) (GetWinFlags() & WF_WLO);
  90. bWin30 = (!bWLO && ((WORD) GetVersion()) <= 0x0003);
  91. // !!! Put all this stuff thru soemkind of table so that we can
  92. // save code.
  93. // register all the atoms.
  94. aStdExit = GlobalAddAtom ((LPSTR)"StdExit");
  95. aStdCreate = GlobalAddAtom ((LPSTR)"StdNewDocument");
  96. aStdOpen = GlobalAddAtom ((LPSTR)"StdOpenDocument");
  97. aStdEdit = GlobalAddAtom ((LPSTR)"StdEditDocument");
  98. aStdCreateFromTemplate = GlobalAddAtom ((LPSTR)"StdNewfromTemplate");
  99. aStdClose = GlobalAddAtom ((LPSTR)"StdCloseDocument");
  100. aStdShowItem = GlobalAddAtom ((LPSTR)"StdShowItem");
  101. aStdDoVerbItem = GlobalAddAtom ((LPSTR)"StdDoVerbItem");
  102. aSysTopic = GlobalAddAtom ((LPSTR)"System");
  103. aOLE = GlobalAddAtom ((LPSTR)"OLEsystem");
  104. aStdDocName = GlobalAddAtom ((LPSTR)"StdDocumentName");
  105. aProtocols = GlobalAddAtom ((LPSTR)"Protocols");
  106. aTopics = GlobalAddAtom ((LPSTR)"Topics");
  107. aFormats = GlobalAddAtom ((LPSTR)"Formats");
  108. aStatus = GlobalAddAtom ((LPSTR)"Status");
  109. aEditItems = GlobalAddAtom ((LPSTR)"EditEnvItems");
  110. aTrue = GlobalAddAtom ((LPSTR)"True");
  111. aFalse = GlobalAddAtom ((LPSTR)"False");
  112. aChange = GlobalAddAtom ((LPSTR)"Change");
  113. aSave = GlobalAddAtom ((LPSTR)"Save");
  114. aClose = GlobalAddAtom ((LPSTR)"Close");
  115. // create the proc instances for the required entry pts.
  116. lpSendRenameMsg = MakeProcInstance (SendRenameMsg, hdllInst);
  117. lpSendDataMsg = MakeProcInstance (SendDataMsg, hdllInst);
  118. lpFindItemWnd = MakeProcInstance (FindItemWnd, hdllInst);
  119. lpItemCallBack = MakeProcInstance (ItemCallBack, hdllInst);
  120. lpTerminateClients = MakeProcInstance (TerminateClients, hdllInst);
  121. lpTerminateDocClients = MakeProcInstance (TerminateDocClients, hdllInst);
  122. lpDeleteClientInfo = MakeProcInstance (DeleteClientInfo, hdllInst);
  123. lpEnumForTerminate = MakeProcInstance (EnumForTerminate , hdllInst);
  124. // register the clipboard formats
  125. cfNative = RegisterClipboardFormat("Native");
  126. cfBinary = RegisterClipboardFormat("Binary");
  127. cfLink = RegisterClipboardFormat("ObjectLink");
  128. cfOwnerLink = RegisterClipboardFormat("OwnerLink");
  129. wc.style = NULL;
  130. wc.cbClsExtra = 0;
  131. wc.cbWndExtra = sizeof(LONG) + //Ask for extra space for storing the
  132. //ptr to srvr/doc/iteminfo.
  133. sizeof (WORD) + // for LE chars
  134. sizeof (WORD); // for keeping the hDLLInst.
  135. wc.hInstance = hInst;
  136. wc.hIcon = NULL;
  137. wc.hCursor = NULL;
  138. wc.hbrBackground= NULL;
  139. wc.lpszMenuName = NULL;
  140. // Srvr window class
  141. wc.lpfnWndProc = SrvrWndProc;
  142. wc.lpszClassName= SRVR_CLASS;
  143. if (!RegisterClass(&wc))
  144. return 0;
  145. // document window class
  146. wc.lpfnWndProc = DocWndProc;
  147. wc.lpszClassName = DOC_CLASS;
  148. if (!RegisterClass(&wc))
  149. return 0;
  150. // Item (object) window class
  151. wc.lpfnWndProc = ItemWndProc;
  152. wc.lpszClassName = ITEM_CLASS;
  153. wc.cbWndExtra = sizeof(LONG); // for items do not need extra stuff.
  154. if (!RegisterClass(&wc))
  155. return 0;
  156. if (!bWin30) {
  157. HANDLE hModule;
  158. if (hModule = GetModuleHandle ("GDI"))
  159. lpfnSetMetaFileBitsBetter
  160. = GetProcAddress (hModule,
  161. (LPSTR) MAKELONG(ORD_SetMetaFileBitsBetter, 0));
  162. if (hModule = GetModuleHandle ("KERNEL"))
  163. lpfnIsTask
  164. = GetProcAddress (hModule, (LPSTR) MAKELONG(ORD_IsTask, 0));
  165. }
  166. if (cbHeapSize != 0)
  167. UnlockData(0);
  168. return 1;
  169. }
  170. VOID FAR PASCAL WEP (nParameter)
  171. int nParameter;
  172. {
  173. Puts("LibExit");
  174. if (nParameter == WEP_SYSTEM_EXIT)
  175. DEBUG_OUT ("---L&E DLL EXIT on system exit---",0)
  176. else {
  177. if (nParameter == WEP_FREE_DLL)
  178. DEBUG_OUT ("---L&E DLL EXIT---",0)
  179. else
  180. return;
  181. }
  182. // free the global atoms.
  183. if (aStdExit)
  184. GlobalDeleteAtom (aStdExit);
  185. if (aStdCreate)
  186. GlobalDeleteAtom (aStdCreate);
  187. if (aStdOpen)
  188. GlobalDeleteAtom (aStdOpen);
  189. if (aStdEdit)
  190. GlobalDeleteAtom (aStdEdit);
  191. if (aStdCreateFromTemplate)
  192. GlobalDeleteAtom (aStdCreateFromTemplate);
  193. if (aStdClose)
  194. GlobalDeleteAtom (aStdClose);
  195. if (aStdShowItem)
  196. GlobalDeleteAtom (aStdShowItem);
  197. if (aStdDoVerbItem)
  198. GlobalDeleteAtom (aStdDoVerbItem);
  199. if (aSysTopic)
  200. GlobalDeleteAtom (aSysTopic);
  201. if (aOLE)
  202. GlobalDeleteAtom (aOLE);
  203. if (aStdDocName)
  204. GlobalDeleteAtom (aStdDocName);
  205. if (aProtocols)
  206. GlobalDeleteAtom (aProtocols);
  207. if (aTopics)
  208. GlobalDeleteAtom (aTopics);
  209. if (aFormats)
  210. GlobalDeleteAtom (aFormats);
  211. if (aStatus)
  212. GlobalDeleteAtom (aStatus);
  213. if (aEditItems)
  214. GlobalDeleteAtom (aEditItems);
  215. if (aTrue)
  216. GlobalDeleteAtom (aTrue);
  217. if (aFalse)
  218. GlobalDeleteAtom (aFalse);
  219. if (aChange)
  220. GlobalDeleteAtom (aChange);
  221. if (aSave)
  222. GlobalDeleteAtom (aSave);
  223. if (aClose)
  224. GlobalDeleteAtom (aClose);
  225. // !!! for some reason these FreeprocInstances are crashing the system.
  226. #if 0
  227. FreeProcInstance (lpSendRenameMsg);
  228. FreeProcInstance (lpSendDataMsg);
  229. FreeProcInstance (lpFindItemWnd);
  230. FreeProcInstance (lpItemCallBack);
  231. FreeProcInstance (lpTerminateClients);
  232. FreeProcInstance (lpTerminateDocClients);
  233. FreeProcInstance (lpDeleteClientInfo);
  234. FreeProcInstance (EnumForTerminate);
  235. #endif
  236. }
  237. #ifdef FIREWALLS
  238. void SetOleFlags()
  239. {
  240. char buffer[80];
  241. if(GetProfileString ("OleDll",
  242. "Puts","", (LPSTR)buffer, 80))
  243. ole_flags = DEBUG_PUTS;
  244. else
  245. ole_flags = 0;
  246. if(GetProfileString ("OleDll",
  247. "DEBUG_OUT","", (LPSTR)buffer, 80))
  248. ole_flags |= DEBUG_DEBUG_OUT;
  249. }
  250. #endif