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.

290 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. faxui.c
  5. Abstract:
  6. Common routines for fax driver user interface
  7. Environment:
  8. Fax driver user interface
  9. Revision History:
  10. 01/09/96 -davidx-
  11. Created it.
  12. mm/dd/yy -author-
  13. description
  14. --*/
  15. #include "faxui.h"
  16. #include "forms.h"
  17. #include <shlobj.h>
  18. #include <faxres.h>
  19. #include <delayimp.h>
  20. #ifdef UNICODE
  21. #include <shfusion.h>
  22. #endif // UNICODE
  23. HANDLE g_hResource = NULL; // Resource DLL instance handle
  24. HANDLE g_hModule = NULL; // DLL instance handle
  25. HANDLE g_hFxsApiModule = NULL; // FXSAPI.DLL instance handle
  26. HANDLE g_hFxsTiffModule = NULL; // FXSTIFF.DLL instance handle
  27. INT _debugLevel = 1; // for debuggping purposes
  28. BOOL g_bDllInitialied = FALSE; // TRUE if the DLL successfuly initialized
  29. char g_szDelayLoadFxsApiName[64] = {0}; // Case sensitive name of FxsApi.dll for delay load mechanism
  30. char g_szDelayLoadFxsTiffName[64] = {0}; // Case sensitive name of FxsTiff.dll for delay load mechanism
  31. #ifdef UNICODE
  32. BOOL g_bSHFusionInitialized = FALSE; // Fusion initialization flag
  33. #endif // UNICODE
  34. FARPROC WINAPI DelayLoadHandler(unsigned dliNotify,PDelayLoadInfo pdli)
  35. {
  36. switch (dliNotify)
  37. {
  38. case dliNotePreLoadLibrary:
  39. if(!g_hFxsApiModule || !g_hFxsTiffModule)
  40. {
  41. Assert(FALSE);
  42. }
  43. if (_strnicmp(pdli->szDll, FAX_API_MODULE_NAME_A, strlen(FAX_API_MODULE_NAME_A))==0)
  44. {
  45. //
  46. // Save the sensitive name DLL name for later use
  47. //
  48. strncpy(g_szDelayLoadFxsApiName, pdli->szDll, ARR_SIZE(g_szDelayLoadFxsApiName)-1);
  49. // trying to load FXSAPI.DLL
  50. return g_hFxsApiModule;
  51. }
  52. if (_strnicmp(pdli->szDll, FAX_TIFF_MODULE_NAME_A, strlen(FAX_TIFF_MODULE_NAME_A))==0)
  53. {
  54. //
  55. // Save the sensitive name DLL name for later use
  56. //
  57. strncpy(g_szDelayLoadFxsTiffName, pdli->szDll, ARR_SIZE(g_szDelayLoadFxsTiffName)-1);
  58. // trying to load FXSAPI.DLL
  59. return g_hFxsTiffModule;
  60. }
  61. }
  62. return 0;
  63. }
  64. PfnDliHook __pfnDliNotifyHook = DelayLoadHandler;
  65. BOOL
  66. DllMain(
  67. HANDLE hModule,
  68. ULONG ulReason,
  69. PCONTEXT pContext
  70. )
  71. /*++
  72. Routine Description:
  73. DLL initialization procedure.
  74. Arguments:
  75. hModule - DLL instance handle
  76. ulReason - Reason for the call
  77. pContext - Pointer to context (not used by us)
  78. Return Value:
  79. TRUE if DLL is initialized successfully, FALSE otherwise.
  80. --*/
  81. {
  82. switch (ulReason) {
  83. case DLL_PROCESS_ATTACH:
  84. DisableThreadLibraryCalls(hModule);
  85. g_hModule = hModule;
  86. g_hResource = GetResInstance(hModule);
  87. if(!g_hResource)
  88. {
  89. return FALSE;
  90. }
  91. break;
  92. case DLL_PROCESS_DETACH:
  93. HeapCleanup();
  94. FreeResInstance();
  95. break;
  96. }
  97. return TRUE;
  98. }
  99. BOOL
  100. InitializeDll()
  101. {
  102. INITCOMMONCONTROLSEX CommonControlsEx = {sizeof(INITCOMMONCONTROLSEX),
  103. ICC_WIN95_CLASSES|ICC_DATE_CLASSES };
  104. if(g_bDllInitialied)
  105. {
  106. return TRUE;
  107. }
  108. // load FXSAPI.DLL
  109. g_hFxsApiModule = LoadLibraryFromLocalFolder(FAX_API_MODULE_NAME, g_hModule);
  110. if(!g_hFxsApiModule)
  111. {
  112. return FALSE;
  113. }
  114. // load FXSTIFF.DLL
  115. g_hFxsTiffModule = LoadLibraryFromLocalFolder(FAX_TIFF_MODULE_NAME, g_hModule);
  116. if(!g_hFxsTiffModule)
  117. {
  118. FreeLibrary(g_hFxsApiModule);
  119. g_hFxsApiModule = NULL;
  120. return FALSE;
  121. }
  122. #ifdef UNICODE
  123. if (!SHFusionInitializeFromModuleID(g_hModule, SXS_MANIFEST_RESOURCE_ID))
  124. {
  125. Verbose(("SHFusionInitializeFromModuleID failed"));
  126. }
  127. else
  128. {
  129. g_bSHFusionInitialized = TRUE;
  130. }
  131. #endif // UNICODE
  132. if (!InitCommonControlsEx(&CommonControlsEx))
  133. {
  134. Verbose(("InitCommonControlsEx failed"));
  135. return FALSE;
  136. }
  137. g_bDllInitialied = TRUE;
  138. return TRUE;
  139. } // InitializeDll
  140. VOID
  141. UnInitializeDll()
  142. {
  143. #ifdef UNICODE
  144. if (g_bSHFusionInitialized)
  145. {
  146. SHFusionUninitialize();
  147. g_bSHFusionInitialized = FALSE;
  148. }
  149. #endif // UNICODE
  150. }
  151. INT
  152. DisplayMessageDialog(
  153. HWND hwndParent,
  154. UINT type,
  155. INT titleStrId,
  156. INT formatStrId,
  157. ...
  158. )
  159. /*++
  160. Routine Description:
  161. Display a message dialog box
  162. Arguments:
  163. hwndParent - Specifies a parent window for the error message dialog
  164. titleStrId - Title string (could be a string resource ID)
  165. formatStrId - Message format string (could be a string resource ID)
  166. ...
  167. Return Value:
  168. NONE
  169. --*/
  170. {
  171. LPTSTR pTitle, pFormat, pMessage;
  172. INT result;
  173. va_list ap;
  174. pTitle = pFormat = pMessage = NULL;
  175. if ((pTitle = AllocStringZ(MAX_TITLE_LEN)) &&
  176. (pFormat = AllocStringZ(MAX_STRING_LEN)) &&
  177. (pMessage = AllocStringZ(MAX_MESSAGE_LEN)))
  178. {
  179. //
  180. // Load dialog box title string resource
  181. //
  182. if (titleStrId == 0)
  183. titleStrId = IDS_ERROR_DLGTITLE;
  184. if(!LoadString(g_hResource, titleStrId, pTitle, MAX_TITLE_LEN))
  185. {
  186. Assert(FALSE);
  187. }
  188. //
  189. // Load message format string resource
  190. //
  191. if(!LoadString(g_hResource, formatStrId, pFormat, MAX_STRING_LEN))
  192. {
  193. Assert(FALSE);
  194. }
  195. //
  196. // Compose the message string
  197. //
  198. va_start(ap, formatStrId);
  199. wvsprintf(pMessage, pFormat, ap);
  200. va_end(ap);
  201. //
  202. // Display the message box
  203. //
  204. if (type == 0)
  205. type = MB_OK | MB_ICONERROR;
  206. result = AlignedMessageBox(hwndParent, pMessage, pTitle, type);
  207. } else {
  208. MessageBeep(MB_ICONHAND);
  209. result = 0;
  210. }
  211. MemFree(pTitle);
  212. MemFree(pFormat);
  213. MemFree(pMessage);
  214. return result;
  215. }