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.

194 lines
4.2 KiB

  1. /*++
  2. Copyright (C) 1999- Microsoft Corporation
  3. Module Name:
  4. dllmain.cpp
  5. Abstract:
  6. This module implements the dll exported APIs
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. #include "pch.h"
  12. #include <locale.h>
  13. HINSTANCE g_hInst;
  14. //
  15. // Entry point of this transport DLL
  16. // Input:
  17. // hInstance -- Instance handle of this dll
  18. // dwReason -- reason why this entry was called.
  19. // lpReserved -- reserved!
  20. //
  21. // Output:
  22. // TRUE if our initialization went well
  23. // FALSE if for GetLastError() reason, we failed.
  24. //
  25. BOOL
  26. APIENTRY
  27. DllMain(
  28. HINSTANCE hInstance,
  29. DWORD dwReason,
  30. LPVOID lpReserved
  31. )
  32. {
  33. switch (dwReason)
  34. {
  35. case DLL_PROCESS_ATTACH:
  36. DisableThreadLibraryCalls(hInstance);
  37. g_hInst = hInstance;
  38. //
  39. // Set the locale to system default so that wcscmp and similary functions
  40. // would work on non-unicode platforms(Millenium, for example).
  41. //
  42. setlocale(LC_ALL, "");
  43. break;
  44. case DLL_PROCESS_DETACH:
  45. break;
  46. default:
  47. break;
  48. }
  49. return TRUE;
  50. }
  51. STDAPI
  52. DllCanUnloadNow(void)
  53. {
  54. return CClassFactory::CanUnloadNow();
  55. }
  56. //
  57. // This api returns an inteface on the given class object
  58. // Input:
  59. // rclsid -- the class object.
  60. //
  61. STDAPI
  62. DllGetClassObject(
  63. REFCLSID rclsid,
  64. REFIID riid,
  65. LPVOID *ppv
  66. )
  67. {
  68. return CClassFactory::GetClassObject(rclsid, riid, ppv);
  69. }
  70. //
  71. // GetDeviceName
  72. //
  73. // This function is called by Co-Installer (not by WIA!), and is used to obtain
  74. // actual device name. This is necessary because all PTP cameras are installed with
  75. // single generic INF file, and this INF file does not provide information about
  76. // device name and manufacturer.
  77. //
  78. // Parameters:
  79. // pwszPortName - this name will be used in CreateFile to open device
  80. // pwszManufacturer - pointer to buffer provided by caller for Manufacturer name, may be NULL
  81. // cchManufacturer - size of buffer, in characters
  82. // pwszModelName - pointer to buffer provided by caller for Model name, may be NULL
  83. // cchModelName - size of buffer, in characters
  84. //
  85. extern "C"
  86. HRESULT
  87. APIENTRY
  88. GetDeviceName(
  89. LPCWSTR pwszPortName,
  90. WCHAR *pwszManufacturer,
  91. DWORD cchManufacturer,
  92. WCHAR *pwszModelName,
  93. DWORD cchModelName
  94. )
  95. {
  96. if (pwszPortName == NULL || pwszPortName[0] == 0)
  97. {
  98. return E_INVALIDARG;
  99. }
  100. HRESULT hr = S_OK;
  101. CPTPCamera *pPTPCamera = NULL;
  102. CPtpDeviceInfo DeviceInfo;
  103. //
  104. // Create a new camera object.
  105. //
  106. pPTPCamera = new CUsbCamera;
  107. if (pPTPCamera == NULL)
  108. {
  109. hr = E_OUTOFMEMORY;
  110. goto Cleanup;
  111. }
  112. //
  113. // Open a connection to the camera
  114. //
  115. hr = pPTPCamera->Open((LPWSTR)pwszPortName, NULL, NULL, NULL, FALSE);
  116. if (FAILED(hr))
  117. {
  118. goto Cleanup;
  119. }
  120. //
  121. // Query the camera for its DeviceInfo
  122. //
  123. hr = pPTPCamera->GetDeviceInfo(&DeviceInfo);
  124. if (FAILED(hr))
  125. {
  126. goto Cleanup;
  127. }
  128. //
  129. // Copy the returned Manufacturer and/or ModelName into the OUT params.
  130. //
  131. if ((pwszManufacturer != NULL) &&
  132. (cchManufacturer > 0) &&
  133. (DeviceInfo.m_cbstrManufacturer.String() != NULL))
  134. {
  135. hr = StringCchCopy(pwszManufacturer, cchManufacturer, DeviceInfo.m_cbstrManufacturer.String());
  136. if (FAILED(hr))
  137. {
  138. goto Cleanup;
  139. }
  140. }
  141. if ((pwszModelName != NULL) &&
  142. (cchModelName > 0) &&
  143. (DeviceInfo.m_cbstrModel.String() != NULL))
  144. {
  145. hr = StringCchCopy(pwszModelName, cchModelName, DeviceInfo.m_cbstrModel.String());
  146. if (FAILED(hr))
  147. {
  148. goto Cleanup;
  149. }
  150. }
  151. Cleanup:
  152. //
  153. // Close the connection to the camera and delete the camera object.
  154. //
  155. if (pPTPCamera)
  156. {
  157. pPTPCamera->Close();
  158. delete pPTPCamera;
  159. }
  160. return hr;
  161. }