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.

209 lines
6.1 KiB

  1. #include <faxres.h>
  2. #include <faxreg.h>
  3. #include "faxutil.h"
  4. #include <tchar.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include "..\admin\faxres\resource.h"
  8. extern "C" {
  9. static HINSTANCE g_hResInst = NULL;
  10. HINSTANCE
  11. WINAPI
  12. GetResInstance(HINSTANCE hModule)
  13. ///////////////////////////////////////////////////////////////////////////////////////
  14. // Function:
  15. // GetResInstance
  16. //
  17. // Purpose:
  18. // Load FxsRes.dll
  19. // FxsRes.dll should be freed with FreeResInstance
  20. //
  21. // Params:
  22. // hModule [in] module handle
  23. //
  24. // Return Value:
  25. // handle of FxsRes.dll or NULL
  26. ///////////////////////////////////////////////////////////////////////////////////////
  27. {
  28. return GetResInst(FAX_RES_FILE, hModule);
  29. } // GetResInstance
  30. HINSTANCE
  31. WINAPI
  32. GetResInst(
  33. LPCTSTR pResFile,
  34. HINSTANCE hModule
  35. )
  36. ///////////////////////////////////////////////////////////////////////////////////////
  37. // Function:
  38. // GetResInstance
  39. //
  40. // Purpose:
  41. // Load file and store the handle in the global g_hResInst
  42. // The file should be freed with FreeResInstance
  43. //
  44. // Params:
  45. // pResFile [in] resource DLL file name
  46. // hModule [in] module handle
  47. // Return Value:
  48. // handle to the loaded file or NULL
  49. ///////////////////////////////////////////////////////////////////////////////////////
  50. {
  51. DEBUG_FUNCTION_NAME(TEXT("GetResInst"));
  52. if(!pResFile)
  53. {
  54. return NULL;
  55. }
  56. if(!g_hResInst)
  57. {
  58. g_hResInst = LoadLibraryFromLocalFolder(pResFile,hModule);
  59. if(!g_hResInst)
  60. {
  61. DebugPrintEx(DEBUG_ERR,TEXT("LoadLibrary(%s) failed with %d"), pResFile, GetLastError());
  62. //
  63. // Try to load with the standard search algorithm
  64. //
  65. g_hResInst = LoadLibrary(pResFile);
  66. if(!g_hResInst)
  67. {
  68. DebugPrintEx(DEBUG_ERR,TEXT("LoadLibrary(%s) failed with %d"), pResFile, GetLastError());
  69. }
  70. }
  71. }
  72. return g_hResInst;
  73. } // GetResInst
  74. ///////////////////////////////////////////////////////////////////////////////////////
  75. // Function:
  76. // LoadLibraryFromLocalFolder
  77. //
  78. // Purpose:
  79. // Loads a library from the local folder as the calling process.
  80. //
  81. // Params:
  82. // LPCTSTR lpctstrModuleName [in] DLL to load file name (with extension e.g FXSAPI.DLL)
  83. // HINSTANCE hModule [in] module handle
  84. // Return Value:
  85. // handle to the loaded file or NULL
  86. ///////////////////////////////////////////////////////////////////////////////////////
  87. HINSTANCE WINAPI LoadLibraryFromLocalFolder(LPCTSTR lpctstrModuleName,HINSTANCE hModule)
  88. {
  89. DWORD dwRes = 0;
  90. TCHAR szLibraryName[MAX_PATH] = {0};
  91. TCHAR szModuleName[MAX_PATH] = {0};
  92. TCHAR szDrive[_MAX_DRIVE] = {0};
  93. TCHAR szDir[MAX_PATH] = {0};
  94. HMODULE hRetModule = NULL;
  95. DEBUG_FUNCTION_NAME(TEXT("LoadLibraryFromLocalFolder"));
  96. if(!lpctstrModuleName)
  97. {
  98. return NULL;
  99. }
  100. dwRes = GetModuleFileName(hModule,szModuleName,ARR_SIZE(szModuleName)-1);
  101. if(0 == dwRes)
  102. {
  103. DebugPrintEx(DEBUG_ERR,TEXT("GetModuleFileName failed with %d"), GetLastError());
  104. return NULL;
  105. }
  106. _tsplitpath(szModuleName, szDrive, szDir, NULL, NULL);
  107. _sntprintf(szLibraryName, ARR_SIZE(szLibraryName)-1, TEXT("%s%s%s"), szDrive, szDir, lpctstrModuleName);
  108. hRetModule = LoadLibrary(szLibraryName);
  109. if(!hRetModule)
  110. {
  111. DebugPrintEx(DEBUG_ERR,TEXT("LoadLibrary(%s) failed with %d"), szLibraryName, GetLastError());
  112. return NULL;
  113. }
  114. return hRetModule;
  115. }
  116. void
  117. WINAPI
  118. FreeResInstance(void)
  119. {
  120. if(g_hResInst)
  121. {
  122. FreeLibrary(g_hResInst);
  123. g_hResInst = NULL;
  124. }
  125. }
  126. UINT
  127. WINAPI
  128. GetErrorStringId(DWORD ec)
  129. {
  130. DWORD uMsgId;
  131. switch (ec)
  132. {
  133. case RPC_S_INVALID_BINDING:
  134. case EPT_S_CANT_PERFORM_OP:
  135. case RPC_S_ADDRESS_ERROR:
  136. case RPC_S_CALL_CANCELLED:
  137. case RPC_S_CALL_FAILED:
  138. case RPC_S_CALL_FAILED_DNE:
  139. case RPC_S_COMM_FAILURE:
  140. case RPC_S_NO_BINDINGS:
  141. case RPC_S_SERVER_TOO_BUSY:
  142. case RPC_S_SERVER_UNAVAILABLE:
  143. uMsgId = IDS_ERR_CONNECTION_FAILED;
  144. break;
  145. case FAX_ERR_DIRECTORY_IN_USE:
  146. uMsgId = IDS_ERR_DIRECTORY_IN_USE;
  147. break;
  148. case ERROR_NOT_ENOUGH_MEMORY:
  149. uMsgId = IDS_ERR_NO_MEMORY;
  150. break;
  151. case ERROR_ACCESS_DENIED:
  152. uMsgId = IDS_ERR_ACCESS_DENIED;
  153. break;
  154. case ERROR_PATH_NOT_FOUND:
  155. uMsgId = IDS_ERR_FOLDER_NOT_FOUND;
  156. break;
  157. case FAXUI_ERROR_DEVICE_LIMIT:
  158. case FAX_ERR_DEVICE_NUM_LIMIT_EXCEEDED:
  159. uMsgId = IDS_ERR_DEVICE_LIMIT;
  160. break;
  161. case FAXUI_ERROR_INVALID_RING_COUNT:
  162. uMsgId = IDS_ERR_INVALID_RING_COUNT;
  163. break;
  164. case FAXUI_ERROR_SELECT_PRINTER:
  165. uMsgId = IDS_ERR_SELECT_PRINTER;
  166. break;
  167. case FAXUI_ERROR_NAME_IS_TOO_LONG:
  168. uMsgId = IDS_ERR_NAME_IS_TOO_LONG;
  169. break;
  170. case FAXUI_ERROR_INVALID_RETRIES:
  171. uMsgId = IDS_ERR_INVALID_RETRIES;
  172. break;
  173. case FAXUI_ERROR_INVALID_RETRY_DELAY:
  174. uMsgId = IDS_ERR_INVALID_RETRY_DELAY;
  175. break;
  176. case FAXUI_ERROR_INVALID_DIRTY_DAYS:
  177. uMsgId = IDS_ERR_INVALID_DIRTY_DAYS;
  178. break;
  179. case FAXUI_ERROR_INVALID_TSID:
  180. uMsgId = IDS_ERR_INVALID_TSID;
  181. break;
  182. case FAXUI_ERROR_INVALID_CSID:
  183. uMsgId = IDS_ERR_INVALID_CSID;
  184. break;
  185. default:
  186. uMsgId = IDS_ERR_OPERATION_FAILED;
  187. break;
  188. }
  189. return uMsgId;
  190. } // GetErrorStringId
  191. } // extern "C"