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.

88 lines
2.5 KiB

  1. #ifndef __ACQTHRD_H_INCLUDED
  2. #define __ACQTHRD_H_INCLUDED
  3. #include <windows.h>
  4. #include "acqmgrcw.h"
  5. #include "evntparm.h"
  6. class CAcquisitionThread
  7. {
  8. private:
  9. CEventParameters m_EventParameters;
  10. private:
  11. explicit CAcquisitionThread( const CEventParameters &EventParameters )
  12. : m_EventParameters( EventParameters )
  13. {
  14. }
  15. ~CAcquisitionThread(void)
  16. {
  17. }
  18. HRESULT Run(void)
  19. {
  20. WIA_PUSHFUNCTION(TEXT("CAcquisitionThread::Run"));
  21. HRESULT hr = CoInitialize(NULL);
  22. if (SUCCEEDED(hr))
  23. {
  24. CAcquisitionManagerControllerWindow::Register( g_hInstance );
  25. HWND hWnd = CAcquisitionManagerControllerWindow::Create( g_hInstance, &m_EventParameters );
  26. if (!hWnd)
  27. {
  28. hr = HRESULT_FROM_WIN32(GetLastError());
  29. if (!SUCCEEDED(hr))
  30. {
  31. WIA_PRINTHRESULT((hr,TEXT("CAcquisitionManagerControllerWindow::Create failed")));
  32. }
  33. }
  34. MSG msg;
  35. while (GetMessage(&msg,0,0,0))
  36. {
  37. TranslateMessage(&msg);
  38. DispatchMessage(&msg);
  39. }
  40. CoUninitialize();
  41. }
  42. return hr;
  43. }
  44. static DWORD ThreadProc( LPVOID pvParam )
  45. {
  46. WIA_PUSHFUNCTION(TEXT("CAcquisitionThread::ThreadProc"));
  47. #if !defined(DBG_GENERATE_PRETEND_EVENT)
  48. _Module.Lock();
  49. #endif
  50. DWORD dwResult = static_cast<DWORD>(E_FAIL);
  51. CAcquisitionThread *pAcquisitionThread = reinterpret_cast<CAcquisitionThread*>(pvParam);
  52. if (pAcquisitionThread)
  53. {
  54. dwResult = static_cast<DWORD>(pAcquisitionThread->Run());
  55. delete pAcquisitionThread;
  56. }
  57. #if !defined(DBG_GENERATE_PRETEND_EVENT)
  58. _Module.Unlock();
  59. #endif
  60. return dwResult;
  61. }
  62. public:
  63. static HANDLE Create( const CEventParameters &EventParameters )
  64. {
  65. WIA_PUSHFUNCTION(TEXT("CAcquisitionThread::Create"));
  66. HANDLE hThreadResult = NULL;
  67. CAcquisitionThread *pAcquisitionThread = new CAcquisitionThread(EventParameters);
  68. if (pAcquisitionThread)
  69. {
  70. DWORD dwThreadId;
  71. hThreadResult = CreateThread( NULL, 0, ThreadProc, pAcquisitionThread, 0, &dwThreadId );
  72. if (!hThreadResult)
  73. {
  74. delete pAcquisitionThread;
  75. }
  76. }
  77. return hThreadResult;
  78. }
  79. };
  80. #endif // __ACQTHRD_H_INCLUDED