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.

186 lines
4.9 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT 2000, MICROSOFT CORP.
  4. *
  5. * TITLE: CCamMicro.cpp
  6. *
  7. * VERSION: 1.0
  8. *
  9. * DATE: Dec 13, 2000
  10. *
  11. * DESCRIPTION:
  12. * Implementation of a simple class that wraps a camera microdriver DLL.
  13. * This class loads the DLL and retrieves the address for the exported
  14. * functions.
  15. *
  16. *******************************************************************************/
  17. #include "pch.h"
  18. //
  19. // These macros make it easier to wrap the DLL functions
  20. //
  21. #define GET_PROC_ADDRESS(fn) \
  22. m_p ## fn = (FP ## fn) GetProcAddress(m_hModule, "WiaMCam" #fn); \
  23. REQUIRE_FILEIO(m_p ## fn != NULL, hr, "Init", "GetProcAddress failed on WiaMCam" #fn);
  24. #define CALL_DLL_FUNCTION(fn, parm) \
  25. HRESULT hr = S_OK; \
  26. if (m_p ## fn) { \
  27. hr = m_p ## fn ## parm; \
  28. } \
  29. else { \
  30. wiauDbgError("CCamMicro::" #fn, "m_p" #fn " not initialized"); \
  31. hr = E_FAIL; \
  32. } \
  33. return hr;
  34. //
  35. // Implementation of DLL wrapper
  36. //
  37. CCamMicro::CCamMicro() :
  38. m_hModule(NULL),
  39. m_pInit(NULL),
  40. m_pUnInit(NULL),
  41. m_pOpen(NULL),
  42. m_pClose(NULL),
  43. m_pGetDeviceInfo(NULL),
  44. m_pReadEvent(NULL),
  45. m_pStopEvents(NULL),
  46. m_pGetItemInfo(NULL),
  47. m_pFreeItemInfo(NULL),
  48. m_pGetThumbnail(NULL),
  49. m_pGetItemData(NULL),
  50. m_pDeleteItem(NULL),
  51. m_pSetItemProt(NULL),
  52. m_pTakePicture(NULL),
  53. m_pStatus(NULL),
  54. m_pReset(NULL)
  55. {
  56. }
  57. CCamMicro::~CCamMicro()
  58. {
  59. if (m_hModule != NULL) {
  60. FreeLibrary(m_hModule);
  61. }
  62. }
  63. HRESULT CCamMicro::Init(PTSTR ptszMicroDriverName, MCAM_DEVICE_INFO **ppDeviceInfo)
  64. {
  65. DBG_FN("CCamMicro::CCamMicro");
  66. HRESULT hr = S_OK;
  67. //
  68. // Load the camera microdriver
  69. //
  70. m_hModule = LoadLibrary(ptszMicroDriverName);
  71. REQUIRE_FILEHANDLE(m_hModule, hr, "CCamMicro::CCamMicro", "LoadLibrary failed");
  72. GET_PROC_ADDRESS(Init);
  73. GET_PROC_ADDRESS(UnInit);
  74. GET_PROC_ADDRESS(Open);
  75. GET_PROC_ADDRESS(Close);
  76. GET_PROC_ADDRESS(GetDeviceInfo);
  77. GET_PROC_ADDRESS(ReadEvent);
  78. GET_PROC_ADDRESS(StopEvents);
  79. GET_PROC_ADDRESS(GetItemInfo);
  80. GET_PROC_ADDRESS(FreeItemInfo);
  81. GET_PROC_ADDRESS(GetThumbnail);
  82. GET_PROC_ADDRESS(GetItemData);
  83. GET_PROC_ADDRESS(DeleteItem);
  84. GET_PROC_ADDRESS(SetItemProt);
  85. GET_PROC_ADDRESS(TakePicture);
  86. GET_PROC_ADDRESS(Status);
  87. GET_PROC_ADDRESS(Reset);
  88. if (m_pInit) {
  89. hr = m_pInit(ppDeviceInfo);
  90. }
  91. else {
  92. wiauDbgError("CCamMicro::Init", "m_pInit not initialized");
  93. hr = E_FAIL;
  94. }
  95. Cleanup:
  96. return hr;
  97. }
  98. HRESULT CCamMicro::UnInit(MCAM_DEVICE_INFO *pDeviceInfo)
  99. {
  100. CALL_DLL_FUNCTION(UnInit, (pDeviceInfo));
  101. }
  102. HRESULT CCamMicro::Open(MCAM_DEVICE_INFO *pDeviceInfo, PWSTR pwszPortName)
  103. {
  104. CALL_DLL_FUNCTION(Open, (pDeviceInfo, pwszPortName));
  105. }
  106. HRESULT CCamMicro::Close(MCAM_DEVICE_INFO *pDeviceInfo)
  107. {
  108. CALL_DLL_FUNCTION(Close, (pDeviceInfo));
  109. }
  110. HRESULT CCamMicro::GetDeviceInfo(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO **ppItemList)
  111. {
  112. CALL_DLL_FUNCTION(GetDeviceInfo, (pDeviceInfo, ppItemList));
  113. }
  114. HRESULT CCamMicro::ReadEvent(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_EVENT_INFO **ppEventList)
  115. {
  116. CALL_DLL_FUNCTION(ReadEvent, (pDeviceInfo, ppEventList));
  117. }
  118. HRESULT CCamMicro::StopEvents(MCAM_DEVICE_INFO *pDeviceInfo)
  119. {
  120. CALL_DLL_FUNCTION(StopEvents, (pDeviceInfo));
  121. }
  122. HRESULT CCamMicro::GetItemInfo(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO *pItemInfo)
  123. {
  124. CALL_DLL_FUNCTION(GetItemInfo, (pDeviceInfo, pItemInfo));
  125. }
  126. HRESULT CCamMicro::FreeItemInfo(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO *pItemInfo)
  127. {
  128. CALL_DLL_FUNCTION(FreeItemInfo, (pDeviceInfo, pItemInfo));
  129. }
  130. HRESULT CCamMicro::GetThumbnail(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO *pItem, INT *pThumbSize, BYTE **ppThumb)
  131. {
  132. CALL_DLL_FUNCTION(GetThumbnail, (pDeviceInfo, pItem, pThumbSize, ppThumb));
  133. }
  134. HRESULT CCamMicro::GetItemData(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO *pItem, UINT uiState, BYTE *pBuf, DWORD dwLength)
  135. {
  136. CALL_DLL_FUNCTION(GetItemData, (pDeviceInfo, pItem, uiState, pBuf, dwLength));
  137. }
  138. HRESULT CCamMicro::DeleteItem(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO *pItem)
  139. {
  140. CALL_DLL_FUNCTION(DeleteItem, (pDeviceInfo, pItem));
  141. }
  142. HRESULT CCamMicro::SetItemProt(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO *pItem, BOOL bReadOnly)
  143. {
  144. CALL_DLL_FUNCTION(SetItemProt, (pDeviceInfo, pItem, bReadOnly));
  145. }
  146. HRESULT CCamMicro::TakePicture(MCAM_DEVICE_INFO *pDeviceInfo, MCAM_ITEM_INFO **ppItemInfo)
  147. {
  148. CALL_DLL_FUNCTION(TakePicture, (pDeviceInfo, ppItemInfo));
  149. }
  150. HRESULT CCamMicro::Status(MCAM_DEVICE_INFO *pDeviceInfo)
  151. {
  152. CALL_DLL_FUNCTION(Status, (pDeviceInfo));
  153. }
  154. HRESULT CCamMicro::Reset(MCAM_DEVICE_INFO *pDeviceInfo)
  155. {
  156. CALL_DLL_FUNCTION(Reset, (pDeviceInfo));
  157. }