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.

241 lines
6.6 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <tchar.h>
  4. #include <windows.h>
  5. #include "wia.h"
  6. #include "sti.h"
  7. //
  8. // Please define MILL if you run it on Millennium
  9. //
  10. #define MILL 1
  11. CLSID CLSID_Handler =
  12. {
  13. 0xA0A45CB0,
  14. 0x8962,
  15. 0x11D2,
  16. 0xA9, 0xD3, 0x00, 0xA0, 0xC9, 0x06, 0x37, 0xD0
  17. };
  18. CLSID CLSID_Handler2 =
  19. {
  20. 0xA0A45CB1,
  21. 0x8962,
  22. 0x11D2,
  23. 0xA9, 0xD3, 0x00, 0xA0, 0xC9, 0x06, 0x37, 0xD0
  24. };
  25. GUID GUID_Connected =
  26. {
  27. 0xa28bbade,
  28. 0x64b6,
  29. 0x11d2,
  30. 0xa2, 0x31, 0x0, 0xc0, 0x4f, 0xa3, 0x18, 0x9
  31. };
  32. GUID GUID_DisConnected =
  33. {
  34. 0x143e4e83,
  35. 0x6497,
  36. 0x11d2,
  37. 0xa2, 0x31, 0x0, 0xc0, 0x4f, 0xa3, 0x18, 0x9
  38. };
  39. int __cdecl main(int argc, char *argv[])
  40. {
  41. HRESULT hr;
  42. IWiaDevMgr *pIDevMgr;
  43. BSTR bstrName;
  44. BSTR bstrDescription;
  45. BSTR bstrIcon;
  46. BSTR bstrDeviceID;
  47. IWiaItem *pIRootItem;
  48. IEnumWIA_DEV_CAPS *pIEnum;
  49. WIA_EVENT_HANDLER wiaHandler;
  50. ULONG ulFetched;
  51. BSTR bstrProgram;
  52. CoInitialize(NULL);
  53. hr = CoCreateInstance(
  54. CLSID_WiaDevMgr,
  55. NULL,
  56. CLSCTX_LOCAL_SERVER,
  57. IID_IWiaDevMgr,
  58. (void**)&pIDevMgr);
  59. //
  60. // Device 0001 on my mill machine and 0005 on my WIN2K is a DC260
  61. //
  62. #ifdef MILL
  63. bstrDeviceID = SysAllocString(L"Image\\0000");
  64. #else
  65. bstrDeviceID = SysAllocString(
  66. L"{6BDD1FC6-810F-11D0-BEC7-08002BE2092F}\\0001");
  67. #endif
  68. bstrName = SysAllocString(L"Download manager");
  69. bstrDescription = SysAllocString(L"Microsoft Download manager");
  70. bstrIcon = SysAllocString(L"downmgr.exe,-1000");
  71. //
  72. // Register a program
  73. //
  74. bstrProgram = SysAllocString(L"c:\\WINNT\\system32\\notepad.exe");
  75. hr = pIDevMgr->RegisterEventCallbackProgram(
  76. WIA_REGISTER_EVENT_CALLBACK,
  77. NULL,
  78. &GUID_Connected,
  79. bstrProgram,
  80. bstrName,
  81. bstrDescription,
  82. bstrIcon);
  83. hr = pIDevMgr->RegisterEventCallbackProgram(
  84. WIA_SET_DEFAULT_HANDLER,
  85. bstrDeviceID,
  86. &GUID_Connected,
  87. bstrProgram,
  88. NULL,
  89. NULL,
  90. NULL);
  91. hr = pIDevMgr->RegisterEventCallbackProgram(
  92. WIA_UNREGISTER_EVENT_CALLBACK,
  93. bstrDeviceID,
  94. &GUID_Connected,
  95. bstrProgram,
  96. NULL,
  97. NULL,
  98. NULL);
  99. //
  100. // Register 2 handlers
  101. //
  102. hr = pIDevMgr->RegisterEventCallbackCLSID(
  103. WIA_REGISTER_EVENT_CALLBACK,
  104. NULL,
  105. &WIA_EVENT_DEVICE_CONNECTED,
  106. &CLSID_Handler,
  107. bstrName,
  108. bstrDescription,
  109. bstrIcon);
  110. SysFreeString(bstrIcon);
  111. bstrIcon = SysAllocString(L"downmgr.exe,-1001");
  112. hr = pIDevMgr->RegisterEventCallbackCLSID(
  113. WIA_REGISTER_EVENT_CALLBACK,
  114. NULL,
  115. &WIA_EVENT_DEVICE_DISCONNECTED,
  116. &CLSID_Handler,
  117. bstrName,
  118. bstrDescription,
  119. bstrIcon);
  120. SysFreeString(bstrIcon);
  121. bstrIcon = SysAllocString(L"downmgr.exe,-1002");
  122. hr = pIDevMgr->RegisterEventCallbackCLSID(
  123. WIA_REGISTER_EVENT_CALLBACK,
  124. NULL,
  125. &GUID_ScanImage,
  126. &CLSID_Handler,
  127. bstrName,
  128. bstrDescription,
  129. bstrIcon);
  130. hr = pIDevMgr->RegisterEventCallbackCLSID(
  131. WIA_SET_DEFAULT_HANDLER,
  132. bstrDeviceID,
  133. &WIA_EVENT_DEVICE_CONNECTED,
  134. &CLSID_Handler,
  135. NULL, // Name, description, Icon are not needed
  136. NULL,
  137. NULL);
  138. hr = pIDevMgr->RegisterEventCallbackCLSID(
  139. WIA_SET_DEFAULT_HANDLER,
  140. bstrDeviceID,
  141. &WIA_EVENT_DEVICE_DISCONNECTED,
  142. &CLSID_Handler,
  143. NULL, // Description and Icon is not necessary
  144. NULL,
  145. NULL);
  146. //
  147. // Register another handler for the 0001
  148. //
  149. hr = pIDevMgr->RegisterEventCallbackCLSID(
  150. WIA_REGISTER_EVENT_CALLBACK,
  151. bstrDeviceID,
  152. &WIA_EVENT_DEVICE_CONNECTED,
  153. &CLSID_Handler2,
  154. bstrName,
  155. bstrDescription,
  156. bstrIcon);
  157. //
  158. // Create the device 0005
  159. //
  160. hr = pIDevMgr->CreateDevice(
  161. bstrDeviceID,
  162. &pIRootItem);
  163. hr = pIRootItem->EnumRegisterEventInfo(
  164. 0,
  165. &GUID_Connected,
  166. &pIEnum);
  167. if (hr == S_OK) {
  168. //
  169. // There will be at least one handler
  170. //
  171. do {
  172. hr = pIEnum->Next(1, &wiaHandler, &ulFetched);
  173. } while (hr == S_OK);
  174. }
  175. //
  176. // Delete the handler specific to a device
  177. //
  178. hr = pIDevMgr->RegisterEventCallbackCLSID(
  179. WIA_UNREGISTER_EVENT_CALLBACK,
  180. bstrDeviceID,
  181. &WIA_EVENT_DEVICE_DISCONNECTED,
  182. &CLSID_Handler,
  183. NULL,
  184. NULL,
  185. NULL);
  186. //
  187. // Delete the handler globally from all the devices
  188. //
  189. hr = pIDevMgr->RegisterEventCallbackCLSID(
  190. WIA_UNREGISTER_EVENT_CALLBACK,
  191. NULL,
  192. &WIA_EVENT_DEVICE_CONNECTED,
  193. &CLSID_Handler,
  194. NULL,
  195. NULL,
  196. NULL);
  197. //
  198. // Garbage collection
  199. //
  200. pIDevMgr->Release();
  201. CoUninitialize();
  202. return (0);
  203. }