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.

363 lines
7.2 KiB

  1. /*++
  2. Copyright (c) 1992-1997 Microsoft Corporation
  3. Module Name:
  4. H323.c
  5. Abstract:
  6. Entry point for H323 TAPI Service Provider.
  7. Environment:
  8. User Mode - Win32
  9. --*/
  10. ///////////////////////////////////////////////////////////////////////////////
  11. // //
  12. // Include files //
  13. // //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #include "globals.h"
  16. #include "provider.h"
  17. #include "config.h"
  18. #include "line.h"
  19. ///////////////////////////////////////////////////////////////////////////////
  20. // //
  21. // Global variables //
  22. // //
  23. ///////////////////////////////////////////////////////////////////////////////
  24. CRITICAL_SECTION g_GlobalLock;
  25. HINSTANCE g_hInstance;
  26. WCHAR * g_pwszProviderInfo = NULL;
  27. WCHAR * g_pwszLineName = NULL;
  28. ///////////////////////////////////////////////////////////////////////////////
  29. // //
  30. // Private prototypes //
  31. // //
  32. ///////////////////////////////////////////////////////////////////////////////
  33. BOOL
  34. WINAPI
  35. CCDllMain(
  36. PVOID DllHandle,
  37. ULONG Reason,
  38. LPVOID lpReserved
  39. );
  40. BOOL
  41. WINAPI
  42. H245DllMain(
  43. PVOID DllHandle,
  44. ULONG Reason,
  45. LPVOID lpReserved
  46. );
  47. BOOL
  48. WINAPI
  49. H245WSDllMain(
  50. PVOID DllHandle,
  51. ULONG Reason,
  52. LPVOID lpReserved
  53. );
  54. ///////////////////////////////////////////////////////////////////////////////
  55. // //
  56. // Private procedures //
  57. // //
  58. ///////////////////////////////////////////////////////////////////////////////
  59. BOOL
  60. H323LoadStrings(
  61. )
  62. /*++
  63. Routine Description:
  64. Loads strings from resource table.
  65. Arguments:
  66. None.
  67. Return Values:
  68. Returns true if successful.
  69. --*/
  70. {
  71. DWORD dwNumBytes;
  72. DWORD dwNumChars;
  73. WCHAR wszBuffer[256];
  74. // load string into buffer
  75. dwNumChars = LoadStringW(
  76. g_hInstance,
  77. IDS_LINENAME,
  78. wszBuffer,
  79. sizeof(wszBuffer)
  80. );
  81. // determine memory needed
  82. dwNumBytes = (dwNumChars + 1) * sizeof(WCHAR);
  83. // allocate memory for unicode string
  84. g_pwszLineName = H323HeapAlloc(dwNumBytes);
  85. // validate pointer
  86. if (g_pwszLineName == NULL) {
  87. H323DBG((
  88. DEBUG_LEVEL_ERROR,
  89. "could not allocate strings.\n"
  90. ));
  91. // failure
  92. return FALSE;
  93. }
  94. // copy loaded string into buffer
  95. memcpy(g_pwszLineName, wszBuffer, dwNumBytes);
  96. // load string into buffer
  97. dwNumChars = LoadStringW(
  98. g_hInstance,
  99. IDS_PROVIDERNAME,
  100. wszBuffer,
  101. sizeof(wszBuffer)
  102. );
  103. // determine memory needed
  104. dwNumBytes = (dwNumChars + 1) * sizeof(WCHAR);
  105. // allocate memory for unicode string
  106. g_pwszProviderInfo = H323HeapAlloc(dwNumBytes);
  107. // validate pointer
  108. if (g_pwszProviderInfo == NULL) {
  109. H323DBG((
  110. DEBUG_LEVEL_ERROR,
  111. "could not allocate strings.\n"
  112. ));
  113. // failure
  114. return FALSE;
  115. }
  116. // copy loaded string into buffer
  117. memcpy(g_pwszProviderInfo, wszBuffer, dwNumBytes);
  118. // success
  119. return TRUE;
  120. }
  121. BOOL
  122. H323UnloadStrings(
  123. )
  124. /*++
  125. Routine Description:
  126. Unloads strings from resource table.
  127. Arguments:
  128. None.
  129. Return Values:
  130. Returns true if successful.
  131. --*/
  132. {
  133. // validate string pointer
  134. if (g_pwszLineName != NULL) {
  135. // release memory consumed
  136. H323HeapFree(g_pwszLineName);
  137. // re-initialize pointer
  138. g_pwszLineName = NULL;
  139. }
  140. // validate string pointer
  141. if (g_pwszProviderInfo != NULL) {
  142. // release memory consumed
  143. H323HeapFree(g_pwszProviderInfo);
  144. // re-initialize pointer
  145. g_pwszProviderInfo = NULL;
  146. }
  147. // success
  148. return TRUE;
  149. }
  150. BOOL
  151. H323StartupTSP(
  152. )
  153. /*++
  154. Routine Description:
  155. Loads H.323 TAPI service provider.
  156. Arguments:
  157. None.
  158. Return Values:
  159. Returns true if successful.
  160. --*/
  161. {
  162. __try {
  163. // initialize global lock (and allocate event immediately)
  164. InitializeCriticalSectionAndSpinCount(&g_GlobalLock,H323_SPIN_COUNT);
  165. } __except ((GetExceptionCode() == STATUS_NO_MEMORY)
  166. ? EXCEPTION_EXECUTE_HANDLER
  167. : EXCEPTION_CONTINUE_SEARCH
  168. ) {
  169. // failure
  170. return FALSE;
  171. }
  172. // create heap
  173. if (!H323HeapCreate()) {
  174. // failure
  175. return FALSE;
  176. }
  177. // load resource strings
  178. if (!H323LoadStrings()) {
  179. // failure
  180. return FALSE;
  181. }
  182. // success
  183. return TRUE;
  184. }
  185. BOOL
  186. H323ShutdownTSP(
  187. )
  188. /*++
  189. Routine Description:
  190. Unloads H.323 TAPI service provider.
  191. Arguments:
  192. None.
  193. Return Values:
  194. Returns true if successful.
  195. --*/
  196. {
  197. // unload strings
  198. H323UnloadStrings();
  199. // nuke heap
  200. H323HeapDestroy();
  201. // release global lock resource
  202. DeleteCriticalSection(&g_GlobalLock);
  203. // success
  204. return TRUE;
  205. }
  206. ///////////////////////////////////////////////////////////////////////////////
  207. // //
  208. // Public Procedures //
  209. // //
  210. ///////////////////////////////////////////////////////////////////////////////
  211. BOOL
  212. WINAPI
  213. DllMain(
  214. PVOID DllHandle,
  215. ULONG Reason,
  216. LPVOID lpReserved
  217. )
  218. /*++
  219. Routine Description:
  220. Dll entry point.
  221. Arguments:
  222. Same as DllMain.
  223. Return Values:
  224. Returns true if successful.
  225. --*/
  226. {
  227. BOOL fOk;
  228. // check if new process attaching
  229. if (Reason == DLL_PROCESS_ATTACH) {
  230. // store the handle into a global variable so that
  231. // the UI code can use it.
  232. g_hInstance = (HINSTANCE)DllHandle;
  233. // turn off thread attach messages
  234. DisableThreadLibraryCalls(DllHandle);
  235. // start h323 tsp
  236. fOk = CCDllMain(DllHandle,Reason,lpReserved) &&
  237. H245DllMain(DllHandle,Reason,lpReserved) &&
  238. H245WSDllMain(DllHandle,Reason,lpReserved) &&
  239. H323StartupTSP();
  240. // check if new process detaching
  241. } else if (Reason == DLL_PROCESS_DETACH) {
  242. // stop h323 tsp
  243. fOk = CCDllMain(DllHandle,Reason,lpReserved) &&
  244. H245DllMain(DllHandle,Reason,lpReserved) &&
  245. H245WSDllMain(DllHandle,Reason,lpReserved) &&
  246. H323ShutdownTSP();
  247. }
  248. return fOk;
  249. }