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.

670 lines
19 KiB

  1. /*
  2. * @DEC_COPYRIGHT@
  3. */
  4. /*
  5. * HISTORY
  6. * $Log: h263_dispatch.c,v $
  7. * $EndLog$
  8. */
  9. /*
  10. **++
  11. ** FACILITY: Workstation Multimedia (WMM) v1.0
  12. **
  13. ** FILE NAME: h263_dispatch.c
  14. ** MODULE NAME: h263_dispatch.c
  15. **
  16. ** MODULE DESCRIPTION:
  17. ** H.263 ICM driver message dispatch routine.
  18. **
  19. ** Functions
  20. **
  21. ** DriverProc (Entry point into codec)
  22. ** ICH263Message (ICM message handler. Calls routines in h263.c)
  23. ** ICH263ClientThread (Thread for processing most messages)
  24. ** ICH263ProcessThread (Thread for processing compress/decompress)
  25. **
  26. ** Private functions:
  27. **
  28. ** DESIGN OVERVIEW:
  29. ** Accept the DriverProc message and dispatch to the proper
  30. ** handler.
  31. **
  32. **--
  33. */
  34. #include <stdio.h>
  35. #include <windows.h>
  36. #include "h26x_int.h"
  37. #ifdef _SLIBDEBUG_
  38. #define _DEBUG_ 0 /* detailed debuging statements */
  39. #define _VERBOSE_ 1 /* show progress */
  40. #define _VERIFY_ 1 /* verify correct operation */
  41. #define _WARN_ 1 /* warnings about strange behavior */
  42. #endif
  43. static CRITICAL_SECTION h263CritSect; /* Critical section for multi-thread protection */
  44. static HMODULE ghModule=NULL; /* Global handle to Module */
  45. #define BOGUS_DRIVER_ID -1 /* Used during open on NT */
  46. #ifdef WIN32
  47. #define CHECKANDLOCK(x) if (((void *)lParam1==NULL) || (int)lParam2<sizeof(x)) \
  48. return ((unsigned int)ICERR_BADPARAM);
  49. #define UNLOCK
  50. #else
  51. #define CHECKANDLOCK(x) { \
  52. int size = lParam2; \
  53. if (noChecklParam2 && size < sizeof(x)) \
  54. size = sizeof(x); \
  55. if (((void *)lParam1 == NULL) || size < sizeof(x)) \
  56. return ((unsigned int)ICERR_BADPARAM); \
  57. }
  58. #define UNLOCK
  59. #endif
  60. /***************************************************************************
  61. ***************************************************************************/
  62. MMRESULT CALLBACK ICH263Message(DWORD_PTR driverHandle,
  63. UINT uiMessage,
  64. LPARAM lParam1,
  65. LPARAM lParam2,
  66. H26XINFO *info)
  67. {
  68. ICINFO *icinfo;
  69. LPBITMAPINFOHEADER lpbiIn;
  70. LPBITMAPINFOHEADER lpbiOut;
  71. ICDECOMPRESS *icDecompress;
  72. DWORD biSizeIn;
  73. DWORD biSizeOut;
  74. MMRESULT ret;
  75. _SlibDebug(_DEBUG_,
  76. ScDebugPrintf("ICH263Message(DriverID=%p, message=%d, lParam1=%p,lParam1=%p, info=%p)\n",
  77. driverHandle, uiMessage, lParam1, lParam2, info) );
  78. switch (uiMessage)
  79. {
  80. /*********************************************************************
  81. ICM messages
  82. *********************************************************************/
  83. case ICM_CONFIGURE:
  84. /*
  85. * return ICERR_OK if you will do a configure box, error otherwise
  86. */
  87. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_CONFIGURE:\n") );
  88. if (lParam1 == -1)
  89. return ICH263QueryConfigure(info) ? ICERR_OK :
  90. ICERR_UNSUPPORTED;
  91. else
  92. return ICH263Configure(info);
  93. case ICM_ABOUT:
  94. /*
  95. * return ICERR_OK if you will do a about box, error otherwise
  96. */
  97. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_ABOUT::\n") );
  98. if (lParam1 == -1)
  99. return ICH263QueryAbout(info) ? ICERR_OK :
  100. ICERR_UNSUPPORTED;
  101. else
  102. return ICH263About(info);
  103. case ICM_GETSTATE:
  104. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_GETSTATE::\n") );
  105. if ((LPVOID)lParam1!=NULL) /* getting state size */
  106. {
  107. char *stateinfo=(char *)lParam1; /* for debugging break point */
  108. memset(stateinfo, 0, 0x60);
  109. }
  110. return (0x60);
  111. case ICM_SETSTATE:
  112. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_SETSTATE::\n") );
  113. if ((LPVOID)lParam1!=NULL) /* getting state size */
  114. {
  115. char *stateinfo=(char *)lParam1; /* for debugging break point */
  116. int i=0;
  117. i=i+1;
  118. }
  119. if (info->dwRTP==EC_RTP_MODE_OFF) /* must be NetMeeting, turn on RTP */
  120. info->dwRTP=EC_RTP_MODE_A;
  121. return (0x60);
  122. case ICM_GETINFO:
  123. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_GETINFO::\n") );
  124. icinfo = (ICINFO FAR *)lParam1;
  125. if (icinfo == NULL)
  126. return sizeof(ICINFO);
  127. if ((DWORD)lParam2 < sizeof(ICINFO))
  128. return 0;
  129. ret = ICH263GetInfo(info, icinfo, (DWORD)lParam2);
  130. UNLOCK;
  131. return ret;
  132. case ICM_GETDEFAULTQUALITY:
  133. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_GETDEFAULTQUALITY::\n") );
  134. CHECKANDLOCK(DWORD);
  135. ret = ICH263GetDefaultQuality(info, (DWORD *)lParam1);
  136. UNLOCK;
  137. return ret;
  138. case ICM_GETQUALITY:
  139. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_GETQUALITY::\n") );
  140. CHECKANDLOCK(DWORD);
  141. ret = ICH263GetQuality(info, (DWORD *)lParam1);
  142. UNLOCK;
  143. return ret;
  144. case ICM_SETQUALITY:
  145. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_SETQUALITY::\n") );
  146. CHECKANDLOCK(DWORD);
  147. ret = ICH263SetQuality(info, (DWORD)lParam1);
  148. UNLOCK;
  149. return ret;
  150. case ICM_GETDEFAULTKEYFRAMERATE:
  151. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_GETDEFAULTKEYFRAMERATE:::\n") );
  152. return ((unsigned int)ICERR_UNSUPPORTED);
  153. case DECH26X_CUSTOM_ENCODER_CONTROL:
  154. _SlibDebug(_VERBOSE_, ScDebugPrintf("------DECH26X_CUSTOM_ENCODER_CONTROL:::\n") );
  155. return(ICH263CustomEncoder(info, (DWORD)lParam2, (WORD)lParam2));
  156. /*********************************************************************
  157. compression messages
  158. *********************************************************************/
  159. case ICM_COMPRESS_QUERY:
  160. _SlibDebug(_DEBUG_, ScDebugPrintf("------ICM_COMPRESS_QUERY::\n") );
  161. if ((lpbiIn = (LPBITMAPINFOHEADER)lParam1) == NULL)
  162. return ((unsigned int)ICERR_BADPARAM);
  163. lpbiOut = (LPBITMAPINFOHEADER)lParam2;
  164. _SlibDebug(_DEBUG_, ScDebugPrintf(" lpbiIn: %s\n", BMHtoString(lpbiIn)) );
  165. _SlibDebug(_DEBUG_, ScDebugPrintf(" lpbiOut: %s\n", BMHtoString(lpbiOut)) );
  166. /* Lock the memory - have to lock the structure first, and iff
  167. * that works, lock the rest
  168. */
  169. biSizeIn = lpbiIn->biSize;
  170. if (lpbiOut)
  171. biSizeOut = lpbiOut->biSize;
  172. if ((biSizeIn != sizeof(BITMAPINFOHEADER))
  173. || (lpbiOut && biSizeOut != sizeof(BITMAPINFOHEADER))) {
  174. UNLOCK;
  175. if ((biSizeIn < sizeof(BITMAPINFOHEADER))
  176. || (lpbiOut && (biSizeOut < sizeof(BITMAPINFOHEADER))))
  177. return ((unsigned int)ICERR_BADPARAM);
  178. }
  179. ret = ICH263CompressQuery(info, lpbiIn, lpbiOut);
  180. UNLOCK;
  181. return ret;
  182. case ICM_COMPRESS_BEGIN:
  183. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_COMPRESS_BEGIN::\n") );
  184. lpbiIn = (LPBITMAPINFOHEADER)lParam1;
  185. lpbiOut = (LPBITMAPINFOHEADER)lParam2;
  186. _SlibDebug(_VERBOSE_, ScDebugPrintf(" lpbiIn: %s\n", BMHtoString(lpbiIn)) );
  187. _SlibDebug(_VERBOSE_, ScDebugPrintf(" lpbiOut: %s\n", BMHtoString(lpbiOut)) );
  188. if (lpbiIn == NULL || lpbiOut == NULL)
  189. return ((unsigned int)ICERR_BADPARAM);
  190. /* Lock the memory - have to lock the structure first, and iff
  191. * that works, lock the rest
  192. */
  193. biSizeIn = lpbiIn->biSize;
  194. biSizeOut = lpbiOut->biSize;
  195. if (biSizeIn != sizeof(BITMAPINFOHEADER) ||
  196. biSizeOut != sizeof(BITMAPINFOHEADER))
  197. {
  198. _SlibDebug(_VERBOSE_,
  199. ScDebugPrintf("biSizeIn or biSizeOut > sizeof(BITMAPINFOHEADER)\n") );
  200. UNLOCK;
  201. if ((biSizeIn < sizeof(BITMAPINFOHEADER))
  202. || (biSizeOut < sizeof(BITMAPINFOHEADER)))
  203. return ((unsigned int)ICERR_BADPARAM);
  204. }
  205. ret = ICH263CompressBegin(info, lpbiIn, lpbiOut);
  206. UNLOCK;
  207. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_COMPRESS_BEGIN:: Done\n") );
  208. return ret;
  209. case ICM_COMPRESS_GET_FORMAT:
  210. _SlibDebug(_DEBUG_, ScDebugPrintf("------ICM_COMPRESS_GET_FORMAT::\n") );
  211. /* Nobody uses lpbiIn in this function. Don't lock anything,
  212. * the lower layers will have to do any necessary locking.
  213. */
  214. return ICH263CompressGetFormat(info,
  215. (LPBITMAPINFOHEADER)lParam1,
  216. (LPBITMAPINFOHEADER)lParam2);
  217. case ICM_COMPRESS_GET_SIZE:
  218. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_COMPRESS_GET_SIZE::\n") );
  219. lpbiIn = (LPBITMAPINFOHEADER)lParam1;
  220. lpbiOut = (LPBITMAPINFOHEADER)lParam2;
  221. return(ICH263CompressGetSize(lpbiIn));
  222. case ICM_COMPRESS:
  223. _SlibDebug(_DEBUG_, ScDebugPrintf("------ICM_COMPRESS::\n") );
  224. ret = ICH263Compress(info, (ICCOMPRESS *) lParam1, (DWORD)lParam2);
  225. return ret;
  226. case ICM_COMPRESS_END:
  227. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_COMPRESS_END::\n") );
  228. return ICH263CompressEnd(info);
  229. /*********************************************************************
  230. decompress messages
  231. *********************************************************************/
  232. case ICM_DECOMPRESS_GET_FORMAT:
  233. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_DECOMPRESS_GET_FORMAT::\n") );
  234. /* Nobody uses lpbiIn in this function. Don't lock anything,
  235. * the lower layers will have to do any necessary locking.
  236. */
  237. return ICH263DecompressGetFormat(info,
  238. (LPBITMAPINFOHEADER)lParam1,
  239. (LPBITMAPINFOHEADER)lParam2);
  240. case ICM_DECOMPRESS_GET_PALETTE:
  241. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_DECOMPRESS_GET_PALETTE::\n") );
  242. if ((lpbiIn = (LPBITMAPINFOHEADER)lParam1) == NULL)
  243. return ((unsigned int)ICERR_BADPARAM);
  244. if ((biSizeIn = lpbiIn->biSize) != sizeof(BITMAPINFOHEADER)) {
  245. UNLOCK;
  246. if (biSizeIn < sizeof(BITMAPINFOHEADER))
  247. return (unsigned int)ICERR_BADPARAM;
  248. }
  249. /*ret = ICH263DecompressGetPalette(info,
  250. (LPBITMAPINFOHEADER)lParam1,
  251. (LPBITMAPINFOHEADER)lParam2);
  252. */
  253. ret = (MMRESULT)ICERR_BADPARAM;
  254. UNLOCK;
  255. return ret;
  256. case ICM_DECOMPRESS_SET_PALETTE:
  257. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_DECOMPRESS_SET_PALETTE::\n") );
  258. return ((unsigned int)ICERR_UNSUPPORTED);
  259. case ICM_DECOMPRESS_QUERY:
  260. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_DECOMPRESS_QUERY::\n") );
  261. if ((lpbiIn = (LPBITMAPINFOHEADER)lParam1) == NULL)
  262. return ((unsigned int)ICERR_BADPARAM);
  263. lpbiOut = (LPBITMAPINFOHEADER)lParam2;
  264. _SlibDebug(_VERBOSE_, ScDebugPrintf(" lpbiIn: %s\n", BMHtoString(lpbiIn)) );
  265. _SlibDebug(_VERBOSE_, ScDebugPrintf(" lpbiOut: %s\n", BMHtoString(lpbiOut)) );
  266. /* Lock the memory - have to lock the structure first, and iff
  267. * that works, lock the rest
  268. */
  269. biSizeIn = lpbiIn->biSize;
  270. if (lpbiOut)
  271. biSizeOut = lpbiOut->biSize;
  272. if ((biSizeIn != sizeof(BITMAPINFOHEADER))
  273. || (lpbiOut && biSizeOut != sizeof(BITMAPINFOHEADER))) {
  274. UNLOCK;
  275. if ((biSizeIn < sizeof(BITMAPINFOHEADER))
  276. || (lpbiOut && (biSizeOut < sizeof(BITMAPINFOHEADER))))
  277. return (unsigned int)ICERR_BADPARAM;
  278. }
  279. ret = ICH263DecompressQuery(info, lpbiIn, lpbiOut);
  280. UNLOCK;
  281. return ret;
  282. case ICM_DECOMPRESS_BEGIN:
  283. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_DECOMPRESS_BEGIN::\n") );
  284. if (((lpbiIn = (LPBITMAPINFOHEADER)lParam1) == NULL)
  285. || ((lpbiOut = (LPBITMAPINFOHEADER)lParam2) == NULL))
  286. return ((unsigned int)ICERR_BADPARAM);
  287. /* Lock the memory - have to lock the structure first, and iff
  288. * that works, lock the rest
  289. */
  290. biSizeIn = lpbiIn->biSize;
  291. biSizeOut = lpbiOut->biSize;
  292. if ((biSizeIn != sizeof(BITMAPINFOHEADER))
  293. || (biSizeOut != sizeof(BITMAPINFOHEADER))) {
  294. UNLOCK;
  295. if ((biSizeIn < sizeof(BITMAPINFOHEADER))
  296. || (biSizeOut < sizeof(BITMAPINFOHEADER)))
  297. return ((unsigned int)ICERR_BADPARAM);
  298. }
  299. ret = ICH263DecompressBegin(info, lpbiIn, lpbiOut);
  300. UNLOCK;
  301. return ret;
  302. case ICM_DECOMPRESS:
  303. _SlibDebug(_DEBUG_, ScDebugPrintf("------ICM_DECOMPRESS::\n") );
  304. icDecompress = (ICDECOMPRESS *)(void *)lParam1;
  305. if ((void *)lParam1==NULL && (void *)lParam2==NULL)
  306. return (unsigned int)ICERR_BADPARAM;
  307. ret = ICH263Decompress(info, (ICDECOMPRESS *) lParam1, (DWORD)lParam2);
  308. return ret;
  309. case ICM_DECOMPRESS_END:
  310. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_DECOMPRESS_END::\n") );
  311. ret = ICH263DecompressEnd(info);
  312. return ret;
  313. case ICM_COMPRESS_FRAMES_INFO:
  314. _SlibDebug(_VERBOSE_, ScDebugPrintf("------ICM_COMPRESS_FRAMES_INFO\n") );
  315. if ((LPVOID)lParam1==NULL ||
  316. lParam2<sizeof(ICCOMPRESSFRAMES))
  317. return (unsigned int)ICERR_BADPARAM;
  318. {
  319. ICCOMPRESSFRAMES *cf=(ICCOMPRESSFRAMES*)lParam1;
  320. _SlibDebug(_VERBOSE_,
  321. ScDebugPrintf("Start=%ld, Count=%ld, Quality=%ld, DataRate=%ld (%5.1f Kb/s), KeyRate=%ld, FPS=%4.1f\n",
  322. cf->lStartFrame,cf->lFrameCount,cf->lQuality,
  323. cf->lDataRate, cf->lDataRate*8.0/1000, cf->lKeyRate, cf->dwRate*1.0/cf->dwScale) );
  324. /* info->dwBitrate=cf->lDataRate*8; */
  325. info->dwQuality=cf->lQuality;
  326. /* info->fFrameRate=(float)(cf->dwRate*1.0/cf->dwScale); */
  327. }
  328. return (unsigned int)ICERR_OK;
  329. }
  330. _SlibDebug(_VERBOSE_,
  331. ScDebugPrintf("ICH263Message(DriverID=%p, message=%d, lParam1=%p,lParam1=%p, info=%p) Unsupported\n",
  332. driverHandle, uiMessage, lParam1, lParam2, info) );
  333. return ((unsigned int)ICERR_UNSUPPORTED);
  334. }
  335. /*
  336. **++
  337. ** FUNCTIONAL_NAME: DriverProc
  338. **
  339. ** FUNCTIONAL_DESCRIPTION:
  340. ** main and only entry point for the server into this driver
  341. **
  342. ** FORMAL PARAMETERS:
  343. ** client pointer
  344. ** driverHandle, returned by us on a DRV_OPEN message
  345. ** driverID allocated and passed by the server
  346. ** message to handle
  347. ** parameters
  348. **
  349. ** RETURN VALUE:
  350. **
  351. ** COMMENTS:
  352. **
  353. ** DESIGN:
  354. **
  355. **/
  356. #define DLLEXPORT
  357. MMRESULT DLLEXPORT APIENTRY
  358. DriverProc(
  359. DWORD_PTR dwDriverID,
  360. HDRVR hDriver,
  361. UINT message,
  362. LPARAM lParam1,
  363. LPARAM lParam2
  364. )
  365. {
  366. MMRESULT ret = DRV_OK;
  367. BOOL notfound = FALSE;
  368. H26XINFO *info = NULL;
  369. void *client = 0; /* Dummy client pointer for other calls. */
  370. /*
  371. * On NT, use __try {} __except() {} to catch
  372. * error conditions.
  373. */
  374. #ifdef HANDLE_EXCEPTIONS
  375. __try { /* try..except */
  376. __try { /* try..finally */
  377. #endif
  378. /*
  379. * Protect threads from interfering with each other.
  380. * To protect against a crash at shutdown, make sure
  381. * that the critical section has not been deleted.
  382. */
  383. if( h263CritSect.DebugInfo )
  384. EnterCriticalSection( &h263CritSect ) ;
  385. _SlibDebug(_DEBUG_,
  386. ScDebugPrintf("DriverProc(DriverID=%p,hDriver=%p,message=%d,lParam1=%p,lParam2=%p)\n",
  387. dwDriverID, hDriver, message, lParam1, lParam2) );
  388. switch (message) {
  389. case DRV_LOAD:
  390. ret = DRV_OK;
  391. _SlibDebug(_VERBOSE_, ScDebugPrintf("------DRV_LOAD returns %d\n", ret) );
  392. break;
  393. case DRV_ENABLE:
  394. ret = 0;
  395. _SlibDebug(_VERBOSE_, ScDebugPrintf("------DRV_ENABLE returns %d\n", ret) );
  396. break;
  397. case DRV_DISABLE:
  398. ret = DRV_OK;
  399. _SlibDebug(_VERBOSE_, ScDebugPrintf("------DRV_DISABLE returns %d\n", ret) );
  400. break;
  401. case DRV_FREE:
  402. ret = DRV_OK;
  403. _SlibDebug(_VERBOSE_, ScDebugPrintf("------DRV_FREE returns %d\n", ret) );
  404. break;
  405. case DRV_OPEN:
  406. /* If lParam2 is NULL, then the app is trying to do a CONFIGURE.
  407. * Return BOGUS_DRIVER_ID, since we don't support CONFIGURE.
  408. */
  409. if( lParam2 == (LONG_PTR) NULL )
  410. ret = (MMRESULT)BOGUS_DRIVER_ID;
  411. else /* lParam2 is an ICOPEN structure, let's really open */
  412. ret = (MMRESULT)((ULONG_PTR)ICH263Open((void *) lParam2));
  413. _SlibDebug(_VERBOSE_, ScDebugPrintf("------DRV_OPEN returns %d\n", ret) );
  414. break;
  415. case DRV_CLOSE:
  416. _SlibDebug(_VERBOSE_,
  417. ScDebugPrintf("------DRV_CLOSE. client %d DriverID %p\n",
  418. client, dwDriverID) );
  419. ret = 0 ;
  420. if ((INT_PTR)dwDriverID != BOGUS_DRIVER_ID)
  421. {
  422. info = IChic2info((HIC)dwDriverID);
  423. if (info)
  424. ICH263Close(info, FALSE);
  425. else
  426. ret = ((unsigned int)ICERR_BADHANDLE);
  427. }
  428. break;
  429. case DRV_QUERYCONFIGURE:
  430. /*
  431. * this is a GLOBAL query configure
  432. */
  433. ret = ICH263QueryConfigure(info);
  434. break;
  435. case DRV_CONFIGURE:
  436. /*
  437. * this is a GLOBAL configure ('cause we don't get a configure
  438. * for each of our procs, we must have just one configure)
  439. */
  440. ret = ICH263Configure(info);
  441. break;
  442. case DRV_INSTALL:
  443. case DRV_REMOVE:
  444. case DRV_EXITSESSION:
  445. break;
  446. default:
  447. info = IChic2info((HIC)dwDriverID);
  448. if (info)
  449. ret = ICH263Message(dwDriverID,
  450. message,
  451. lParam1,
  452. lParam2,
  453. info ) ;
  454. else
  455. ret = ((unsigned int)ICERR_BADHANDLE) ;
  456. }
  457. #ifdef HANDLE_EXCEPTIONS
  458. } __finally {
  459. #endif /* HANDLE_EXCEPTIONS */
  460. /*
  461. * Leave the critical section, so we don't
  462. * deadlock.
  463. */
  464. if( h263CritSect.DebugInfo )
  465. LeaveCriticalSection( &h263CritSect );
  466. #ifdef HANDLE_EXCEPTIONS
  467. } /* try..finally */
  468. } __except(EXCEPTION_EXECUTE_HANDLER) {
  469. /*
  470. * NT exception handler. If anything went
  471. * wrong in the __try {} section, we will
  472. * end up here.
  473. */
  474. #if defined(EXCEPTION_MESSAGES) && defined(H263_SUPPORT)
  475. // MessageBox(NULL, "Exception in H263 DriverProc", "Warning", MB_OK);
  476. #elif defined(EXCEPTION_MESSAGES)
  477. // MessageBox(NULL, "Exception in H261 DriverProc", "Warning", MB_OK);
  478. #endif
  479. /*
  480. * Return an error code.
  481. */
  482. return((MMRESULT)ICERR_INTERNAL);
  483. } /* try..except */
  484. #endif /* HANDLE_EXCEPTIONS */
  485. _SlibDebug(_DEBUG_||_VERBOSE_, ScDebugPrintf("return is %d\n", ret) );
  486. return ret;
  487. }
  488. /*
  489. * Dummy DriverPostReply routine, it does nothing.
  490. * It should never be called on NT.
  491. */
  492. DriverPostReply(void *client,
  493. DWORD ret,
  494. DWORD arg )
  495. {
  496. return 0;
  497. }
  498. #ifndef INITCRT
  499. #define INITCRT
  500. #endif
  501. #ifdef INITCRT
  502. BOOL WINAPI _CRT_INIT(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved);
  503. #endif
  504. /*
  505. * This DllEntryPoint is needed on NT in order for
  506. * an application to connect to a dll properly.
  507. */
  508. DLLEXPORT BOOL WINAPI
  509. DllEntryPoint(
  510. HINSTANCE hinstDLL,
  511. DWORD fdwReason,
  512. LPVOID lpReserved)
  513. {
  514. switch (fdwReason) {
  515. case DLL_PROCESS_ATTACH:
  516. /*
  517. * We're being loaded - save our handle in a global.
  518. */
  519. ghModule = (HMODULE) hinstDLL;
  520. /*
  521. * Initialize the Critical Section that we use
  522. * to ensure Threads don't stomp on each other.
  523. */
  524. InitializeCriticalSection( &h263CritSect ) ;
  525. /*
  526. * A Process is also a thread, so deliberately
  527. * fall into DLL_THREAD_ATTACH.
  528. */
  529. case DLL_THREAD_ATTACH:
  530. /*
  531. * A Thread have been created that may
  532. * be calling this DLL.
  533. * Initialize the C run_time library.
  534. */
  535. #ifdef INITCRT
  536. if( !_CRT_INIT( hinstDLL, fdwReason, lpReserved ) )
  537. return FALSE ;
  538. #endif /* INITCRT */
  539. break;
  540. case DLL_PROCESS_DETACH:
  541. /*
  542. * We are shutting down. Perform some cleanup
  543. * so that lingering threads won't try to work
  544. * and maybe access violate.
  545. */
  546. TerminateH263() ;
  547. /*
  548. * Delete the Critical Section that we created
  549. * at load time.
  550. */
  551. DeleteCriticalSection( &h263CritSect ) ;
  552. /*
  553. * A Process is also a thread so deliberately
  554. * fall through to DLL_THREAD_DETACH.
  555. */
  556. case DLL_THREAD_DETACH:
  557. /*
  558. * Close down the C run-time library.
  559. */
  560. #ifdef INITCRT
  561. if( !_CRT_INIT( hinstDLL, fdwReason, lpReserved ) )
  562. return FALSE ;
  563. #endif /* INITCRT */
  564. break;
  565. }
  566. return (TRUE);
  567. }