Source code of Windows XP (NT5)
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.

350 lines
10 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 - 1992 Microsoft Corporation
  9. *
  10. * History:
  11. * Raor (../10/1990) Designed, coded
  12. * curts created portable version for WIN16/32
  13. *
  14. \***************************************************************************/
  15. #include "windows.h"
  16. #include "ole.h"
  17. #include "dde.h"
  18. #include "cmacs.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. VOID FAR PASCAL WEP(int);
  72. #ifdef WIN16
  73. BOOL bProtMode;
  74. BOOL bWLO = FALSE;
  75. BOOL bWin30 = FALSE;
  76. #pragma alloc_text(WEP_TEXT, WEP)
  77. //DLL entry:
  78. int FAR PASCAL LibMain (
  79. HANDLE hInst,
  80. WORD wDataSeg,
  81. WORD cbHeapSize,
  82. LPSTR lpszCmdLine
  83. #endif
  84. #ifdef WIN32 //WIN32
  85. BOOL LibMain(
  86. HANDLE hInst,
  87. ULONG Reason,
  88. PCONTEXT Context
  89. #endif
  90. ){
  91. WNDCLASS wc;
  92. Puts("LibMain");
  93. #ifdef WIN32
  94. UNREFERENCED_PARAMETER(Context);
  95. if (Reason == DLL_PROCESS_DETACH)
  96. {
  97. WEP(0);
  98. return TRUE;
  99. }
  100. else if (Reason != DLL_PROCESS_ATTACH)
  101. return TRUE;
  102. #endif
  103. #ifdef FIREWALLS
  104. SetOleFlags();
  105. #endif
  106. hdllInst = hInst;
  107. #ifdef WIN16
  108. bProtMode = (BOOL) (GetWinFlags() & WF_PMODE & 0x0000FFFF);
  109. bWLO = (BOOL) (GetWinFlags() & WF_WLO);
  110. bWin30 = (!bWLO && ((WORD) GetVersion()) <= 0x0003);
  111. #endif
  112. // !!! Put all this stuff thru soemkind of table so that we can
  113. // save code.
  114. // register all the atoms.
  115. aStdExit = GlobalAddAtom ((LPSTR)"StdExit");
  116. aStdCreate = GlobalAddAtom ((LPSTR)"StdNewDocument");
  117. aStdOpen = GlobalAddAtom ((LPSTR)"StdOpenDocument");
  118. aStdEdit = GlobalAddAtom ((LPSTR)"StdEditDocument");
  119. aStdCreateFromTemplate = GlobalAddAtom ((LPSTR)"StdNewfromTemplate");
  120. aStdClose = GlobalAddAtom ((LPSTR)"StdCloseDocument");
  121. aStdShowItem = GlobalAddAtom ((LPSTR)"StdShowItem");
  122. aStdDoVerbItem = GlobalAddAtom ((LPSTR)"StdDoVerbItem");
  123. aSysTopic = GlobalAddAtom ((LPSTR)"System");
  124. aOLE = GlobalAddAtom ((LPSTR)"OLEsystem");
  125. aStdDocName = GlobalAddAtom ((LPSTR)"StdDocumentName");
  126. aProtocols = GlobalAddAtom ((LPSTR)"Protocols");
  127. aTopics = GlobalAddAtom ((LPSTR)"Topics");
  128. aFormats = GlobalAddAtom ((LPSTR)"Formats");
  129. aStatus = GlobalAddAtom ((LPSTR)"Status");
  130. aEditItems = GlobalAddAtom ((LPSTR)"EditEnvItems");
  131. aTrue = GlobalAddAtom ((LPSTR)"True");
  132. aFalse = GlobalAddAtom ((LPSTR)"False");
  133. aChange = GlobalAddAtom ((LPSTR)"Change");
  134. aSave = GlobalAddAtom ((LPSTR)"Save");
  135. aClose = GlobalAddAtom ((LPSTR)"Close");
  136. // create the proc instances for the required entry pts.
  137. lpSendRenameMsg = (FARPROC)MakeProcInstance (SendRenameMsg, hdllInst);
  138. lpSendDataMsg = (FARPROC)MakeProcInstance (SendDataMsg, hdllInst);
  139. lpFindItemWnd = (FARPROC)MakeProcInstance (FindItemWnd, hdllInst);
  140. lpItemCallBack = (FARPROC)MakeProcInstance (ItemCallBack, hdllInst);
  141. lpTerminateClients = (FARPROC)MakeProcInstance (TerminateClients, hdllInst);
  142. lpTerminateDocClients = (FARPROC)MakeProcInstance (TerminateDocClients, hdllInst);
  143. lpDeleteClientInfo = (FARPROC)MakeProcInstance (DeleteClientInfo, hdllInst);
  144. lpEnumForTerminate = (FARPROC)MakeProcInstance (EnumForTerminate , hdllInst);
  145. // register the clipboard formats
  146. cfNative = (OLECLIPFORMAT)RegisterClipboardFormat("Native");
  147. cfBinary = (OLECLIPFORMAT)RegisterClipboardFormat("Binary");
  148. cfLink = (OLECLIPFORMAT)RegisterClipboardFormat("ObjectLink");
  149. cfOwnerLink = (OLECLIPFORMAT)RegisterClipboardFormat("OwnerLink");
  150. wc.style = 0;
  151. wc.cbClsExtra = 0;
  152. wc.cbWndExtra = sizeof(LONG_PTR) + //Ask for extra space for storing the
  153. //ptr to srvr/doc/iteminfo.
  154. sizeof (WORD) + // for LE chars
  155. sizeof (UINT_PTR); // for keeping the hDLLInst.
  156. wc.hInstance = hInst;
  157. wc.hIcon = NULL;
  158. wc.hCursor = NULL;
  159. wc.hbrBackground= NULL;
  160. wc.lpszMenuName = NULL;
  161. // Srvr window class
  162. wc.lpfnWndProc = SrvrWndProc;
  163. wc.lpszClassName= SRVR_CLASS;
  164. if (!RegisterClass(&wc))
  165. return 0;
  166. // document window class
  167. wc.lpfnWndProc = DocWndProc;
  168. wc.lpszClassName = DOC_CLASS;
  169. if (!RegisterClass(&wc))
  170. return 0;
  171. // Item (object) window class
  172. wc.lpfnWndProc = ItemWndProc;
  173. wc.lpszClassName = ITEM_CLASS;
  174. wc.cbWndExtra = sizeof(LONG_PTR); // for items do not need extra stuff.
  175. if (!RegisterClass(&wc))
  176. return 0;
  177. #ifdef WIN16
  178. if (!bWin30) {
  179. HANDLE hModule;
  180. if (hModule = GetModuleHandle ("GDI"))
  181. lpfnSetMetaFileBitsBetter
  182. = GetProcAddress (hModule,
  183. (LPSTR) MAKELONG(ORD_SetMetaFileBitsBetter, 0));
  184. if (hModule = GetModuleHandle ("KERNEL"))
  185. lpfnIsTask
  186. = GetProcAddress (hModule, (LPSTR) MAKELONG(ORD_IsTask, 0));
  187. }
  188. if (cbHeapSize != 0)
  189. UnlockData(0);
  190. #endif
  191. return 1;
  192. }
  193. VOID APIENTRY WEP (int nParameter)
  194. {
  195. Puts("LibExit");
  196. #ifdef WIN16
  197. if (nParameter == WEP_SYSTEM_EXIT)
  198. DEBUG_OUT ("---L&E DLL EXIT on system exit---",0)
  199. else {
  200. if (nParameter == WEP_FREE_DLL)
  201. DEBUG_OUT ("---L&E DLL EXIT---",0)
  202. else
  203. return;
  204. }
  205. #endif
  206. #ifdef WIN32
  207. UNREFERENCED_PARAMETER(nParameter);
  208. DEBUG_OUT ("---L&E DLL EXIT---",0)
  209. #endif
  210. // free the global atoms.
  211. if (aStdExit)
  212. GlobalDeleteAtom (aStdExit);
  213. if (aStdCreate)
  214. GlobalDeleteAtom (aStdCreate);
  215. if (aStdOpen)
  216. GlobalDeleteAtom (aStdOpen);
  217. if (aStdEdit)
  218. GlobalDeleteAtom (aStdEdit);
  219. if (aStdCreateFromTemplate)
  220. GlobalDeleteAtom (aStdCreateFromTemplate);
  221. if (aStdClose)
  222. GlobalDeleteAtom (aStdClose);
  223. if (aStdShowItem)
  224. GlobalDeleteAtom (aStdShowItem);
  225. if (aStdDoVerbItem)
  226. GlobalDeleteAtom (aStdDoVerbItem);
  227. if (aSysTopic)
  228. GlobalDeleteAtom (aSysTopic);
  229. if (aOLE)
  230. GlobalDeleteAtom (aOLE);
  231. if (aStdDocName)
  232. GlobalDeleteAtom (aStdDocName);
  233. if (aProtocols)
  234. GlobalDeleteAtom (aProtocols);
  235. if (aTopics)
  236. GlobalDeleteAtom (aTopics);
  237. if (aFormats)
  238. GlobalDeleteAtom (aFormats);
  239. if (aStatus)
  240. GlobalDeleteAtom (aStatus);
  241. if (aEditItems)
  242. GlobalDeleteAtom (aEditItems);
  243. if (aTrue)
  244. GlobalDeleteAtom (aTrue);
  245. if (aFalse)
  246. GlobalDeleteAtom (aFalse);
  247. if (aChange)
  248. GlobalDeleteAtom (aChange);
  249. if (aSave)
  250. GlobalDeleteAtom (aSave);
  251. if (aClose)
  252. GlobalDeleteAtom (aClose);
  253. // !!! for some reason these FreeprocInstances are crashing the system.
  254. #if 0
  255. FreeProcInstance (lpSendRenameMsg);
  256. FreeProcInstance (lpSendDataMsg);
  257. FreeProcInstance (lpFindItemWnd);
  258. FreeProcInstance (lpItemCallBack);
  259. FreeProcInstance (lpTerminateClients);
  260. FreeProcInstance (lpTerminateDocClients);
  261. FreeProcInstance (lpDeleteClientInfo);
  262. FreeProcInstance (EnumForTerminate);
  263. #endif
  264. }
  265. #ifdef FIREWALLS
  266. void SetOleFlags()
  267. {
  268. char buffer[80];
  269. if(GetProfileString ("OleDll",
  270. "Puts","", (LPSTR)buffer, 80))
  271. ole_flags = DEBUG_PUTS;
  272. else
  273. ole_flags = 0;
  274. if(GetProfileString ("OleDll",
  275. "DEBUG_OUT","", (LPSTR)buffer, 80))
  276. ole_flags |= DEBUG_DEBUG_OUT;
  277. }
  278. #endif