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.

434 lines
11 KiB

  1. /*++
  2. Copyright (C) 1997-998 Microsoft Corporation
  3. Module Name:
  4. subcli.cxx
  5. Abstract:
  6. Code to test the COM/OleAutomation aspect of the Test Subscriber for
  7. SENS.
  8. Author:
  9. Gopal Parupudi <GopalP>
  10. [Notes:]
  11. optional-notes
  12. Revision History:
  13. GopalP 1/17/1998 Start.
  14. --*/
  15. #include <stdio.h>
  16. #include <ole2.h>
  17. #include <oleauto.h>
  18. #include <initguid.h>
  19. #include <sens.h>
  20. #include <sensevts.h>
  21. #include "sinkguid.hxx"
  22. #define SENS_SERVICE L"SENS.DLL"
  23. #define MAJOR_VER 1
  24. #define MINOR_VER 0
  25. #define DEFAULT_LCID 0x0
  26. int
  27. main(
  28. int argc,
  29. char **argv
  30. )
  31. {
  32. HRESULT hr = S_OK;
  33. IDispatch *pIDispatchNetwork = NULL;
  34. IDispatch *pIDispatchLogon = NULL;
  35. ISensNetwork *pISensNetwork = NULL;
  36. ISensNetwork *pISensLogon = NULL;
  37. ITypeLib *pITypeLib = NULL;
  38. ITypeInfo *pITypeInfo = NULL;
  39. IRecordInfo * pIRecordInfo = NULL;
  40. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  41. printf("CoInitializeEx() returned 0x%x\n", hr);
  42. if (FAILED(hr))
  43. {
  44. goto Cleanup;
  45. }
  46. DISPID dispIDNetwork;
  47. DISPID dispIDLogon;
  48. OLECHAR *name;
  49. printf("--------------------------------------------------------------\n");
  50. hr = CoCreateInstance(
  51. CLSID_SensTestSubscriberNetwork,
  52. NULL,
  53. CLSCTX_LOCAL_SERVER,
  54. IID_IDispatch,
  55. (LPVOID *) &pIDispatchNetwork
  56. );
  57. printf("CoCreateInstance(IDispatchNetwork) returned 0x%x\n", hr);
  58. if (FAILED(hr))
  59. {
  60. goto Cleanup;
  61. }
  62. hr = CoCreateInstance(
  63. CLSID_SensTestSubscriberNetwork,
  64. NULL,
  65. CLSCTX_LOCAL_SERVER,
  66. IID_ISensNetwork,
  67. (LPVOID *) &pISensNetwork
  68. );
  69. printf("CoCreateInstance(ISensNetwork) returned 0x%x\n", hr);
  70. if (FAILED(hr))
  71. {
  72. goto Cleanup;
  73. }
  74. /*
  75. printf("Calling pISensNetwork->ConnectionMade()\n");
  76. pISensNetwork->ConnectionMade(
  77. SysAllocString(L"A dummy Connection Name"),
  78. 0x1234,
  79. NULL
  80. );
  81. printf("Calling pISensNetwork->ConnectionMade() - DONE.\n");
  82. */
  83. name = L"FooFunc";
  84. hr = pIDispatchNetwork->GetIDsOfNames(
  85. IID_NULL,
  86. &name,
  87. 1,
  88. GetUserDefaultLCID(),
  89. &dispIDNetwork
  90. );
  91. printf("GetIDsOfNames(FooFunc) returned 0x%x, dispID = %d\n",
  92. hr, dispIDNetwork);
  93. if (FAILED(hr))
  94. {
  95. goto Cleanup;
  96. }
  97. //
  98. // Call Invoke on a function with 1 argument.
  99. //
  100. BSTR bstrTemp;
  101. VARIANTARG varg;
  102. bstrTemp = SysAllocString(L"A Dummy Connection Name");
  103. VariantInit(&varg);
  104. varg.vt = VT_BSTR;
  105. varg.bstrVal = bstrTemp;
  106. // Fill in the DISPPARAMS structure.
  107. DISPPARAMS param;
  108. param.cArgs = 1;
  109. param.rgvarg = &varg;
  110. param.cNamedArgs = 0;
  111. param.rgdispidNamedArgs = NULL;
  112. hr = pIDispatchNetwork->Invoke(
  113. dispIDNetwork,
  114. IID_NULL,
  115. GetUserDefaultLCID(),
  116. DISPATCH_METHOD,
  117. &param,
  118. NULL,
  119. NULL,
  120. NULL
  121. );
  122. printf("Invoke(FooFunc) returned 0x%x\n", hr);
  123. SysFreeString(bstrTemp);
  124. if (FAILED(hr))
  125. {
  126. goto Cleanup;
  127. }
  128. printf("--------------------------------------------------------------\n");
  129. name = L"ConnectionMadeNoQOCInfo";
  130. hr = pIDispatchNetwork->GetIDsOfNames(
  131. IID_NULL,
  132. &name,
  133. 1,
  134. GetUserDefaultLCID(),
  135. &dispIDNetwork
  136. );
  137. printf("GetIDsOfNames(ConnectionMadeNoQOCInfo) returned 0x%x, dispID = %d\n",
  138. hr, dispIDNetwork);
  139. if (FAILED(hr))
  140. {
  141. goto Cleanup;
  142. }
  143. //
  144. // Call Invoke on a function with 2 arguments (parameters in reverse order).
  145. //
  146. VARIANTARG vargarr[2];
  147. bstrTemp = SysAllocString(L"A Dummy Connection Name");
  148. VariantInit(&vargarr[1]);
  149. vargarr[1].vt = VT_BSTR;
  150. vargarr[1].bstrVal = bstrTemp;
  151. VariantInit(&vargarr[0]);
  152. vargarr[0].vt = VT_UI4;
  153. vargarr[0].ulVal = 0x00000001;
  154. // Fill in the DISPPARAMS structure.
  155. param.cArgs = 2;
  156. param.rgvarg = vargarr;
  157. param.cNamedArgs = 0;
  158. param.rgdispidNamedArgs = NULL;
  159. hr = pIDispatchNetwork->Invoke(
  160. dispIDNetwork,
  161. IID_NULL,
  162. GetUserDefaultLCID(),
  163. DISPATCH_METHOD,
  164. &param,
  165. NULL,
  166. NULL,
  167. NULL
  168. );
  169. printf("Invoke(ConnectionMadeNoQOCInfo) returned 0x%x\n", hr);
  170. SysFreeString(bstrTemp);
  171. if (FAILED(hr))
  172. {
  173. goto Cleanup;
  174. }
  175. printf("--------------------------------------------------------------\n");
  176. hr = CoCreateInstance(
  177. CLSID_SensTestSubscriberLogon,
  178. NULL,
  179. CLSCTX_LOCAL_SERVER,
  180. IID_IDispatch,
  181. (LPVOID *) &pIDispatchLogon
  182. );
  183. printf("CoCreateInstance(IDispatchLogon) returned 0x%x\n", hr);
  184. if (FAILED(hr))
  185. {
  186. goto Cleanup;
  187. }
  188. hr = CoCreateInstance(
  189. CLSID_SensTestSubscriberLogon,
  190. NULL,
  191. CLSCTX_LOCAL_SERVER,
  192. IID_ISensLogon,
  193. (LPVOID *) &pISensLogon
  194. );
  195. printf("CoCreateInstance(ISensLogon) returned 0x%x\n", hr);
  196. if (FAILED(hr))
  197. {
  198. goto Cleanup;
  199. }
  200. name = L"Logon";
  201. hr = pIDispatchLogon->GetIDsOfNames(
  202. IID_NULL,
  203. &name,
  204. 1,
  205. GetUserDefaultLCID(),
  206. &dispIDLogon
  207. );
  208. printf("GetIDsOfNames(Logon) returned 0x%x, dispID = %d\n",
  209. hr, dispIDLogon);
  210. if (FAILED(hr))
  211. {
  212. goto Cleanup;
  213. }
  214. //
  215. // Call Invoke on a function with 1 argument.
  216. //
  217. bstrTemp = SysAllocString(L"REDMOND\\JohnDoe");
  218. VariantInit(&varg);
  219. varg.vt = VT_BSTR;
  220. varg.bstrVal = bstrTemp;
  221. // Fill in the DISPPARAMS structure.
  222. param.cArgs = 1;
  223. param.rgvarg = &varg;
  224. param.cNamedArgs = 0;
  225. param.rgdispidNamedArgs = NULL;
  226. hr = pIDispatchLogon->Invoke(
  227. dispIDLogon,
  228. IID_NULL,
  229. GetUserDefaultLCID(),
  230. DISPATCH_METHOD,
  231. &param,
  232. NULL,
  233. NULL,
  234. NULL
  235. );
  236. printf("Invoke(Logon) returned 0x%x\n", hr);
  237. SysFreeString(bstrTemp);
  238. if (FAILED(hr))
  239. {
  240. goto Cleanup;
  241. }
  242. printf("--------------------------------------------------------------\n");
  243. //
  244. // Call Invoke with multiple arguments and UDT
  245. //
  246. name = L"ConnectionMade";
  247. hr = pIDispatchNetwork->GetIDsOfNames(
  248. IID_NULL,
  249. &name,
  250. 1,
  251. GetUserDefaultLCID(),
  252. &dispIDNetwork
  253. );
  254. printf("GetIDsOfNames(ConnectionMade) returned 0x%x, dispID = %d\n",
  255. hr, dispIDNetwork);
  256. if (FAILED(hr))
  257. {
  258. goto Cleanup;
  259. }
  260. // Get the ITypeInfo pointer.
  261. hr = LoadRegTypeLib(
  262. LIBID_SensEvents,
  263. MAJOR_VER,
  264. MINOR_VER,
  265. DEFAULT_LCID,
  266. &pITypeLib
  267. );
  268. printf("LoadRegTypeLib returned 0x%x\n", hr);
  269. if (FAILED(hr))
  270. {
  271. hr = LoadTypeLib(
  272. SENS_SERVICE,
  273. &pITypeLib
  274. );
  275. printf("LoadTypeLib() returned 0x%x\n", hr);
  276. if (FAILED(hr))
  277. {
  278. goto Cleanup;
  279. }
  280. }
  281. hr = pITypeLib->GetTypeInfo(0, &pITypeInfo);
  282. printf("GetTypeInfo returned 0x%x - (pITypeInfo = 0x%x)\n", hr, pITypeInfo);
  283. if (FAILED(hr))
  284. {
  285. goto Cleanup;
  286. }
  287. hr = GetRecordInfoFromTypeInfo(pITypeInfo, &pIRecordInfo);
  288. printf("GetRecordInfoFromTypeInfo returned 0x%x\n", hr);
  289. if (FAILED(hr))
  290. {
  291. goto Cleanup;
  292. }
  293. VARIANTARG arrvarg[3];
  294. SENS_QOCINFO QOCInfo;
  295. //
  296. // Parameters are filled in the reverse order.
  297. //
  298. VariantInit(&arrvarg[2]);
  299. arrvarg[2].vt = VT_BSTR;
  300. arrvarg[2].bstrVal = SysAllocString(L"A dummy connection name");
  301. VariantInit(&arrvarg[1]);
  302. arrvarg[1].vt = VT_UI4;
  303. arrvarg[1].ulVal = 0x1234abcd;
  304. // Setup QOCInfo.
  305. QOCInfo.ulSize = sizeof(SENS_QOCINFO);
  306. QOCInfo.ulFlags = 0x00000003;
  307. QOCInfo.ulInSpeed = 33600;
  308. QOCInfo.ulOutSpeed = 33600;
  309. VariantInit(&arrvarg[0]);
  310. arrvarg[0].vt = VT_RECORD | VT_BYREF;
  311. arrvarg[0].pRecInfo = pIRecordInfo;
  312. arrvarg[0].pvRecord = &QOCInfo;
  313. // Fill in the DISPPARAMS structure.
  314. param.cArgs = 3;
  315. param.rgvarg = arrvarg;
  316. param.cNamedArgs = 0;
  317. param.rgdispidNamedArgs = NULL;
  318. hr = pIDispatchNetwork->Invoke(
  319. dispIDNetwork,
  320. IID_NULL,
  321. GetUserDefaultLCID(),
  322. DISPATCH_METHOD,
  323. &param,
  324. NULL,
  325. NULL,
  326. NULL
  327. );
  328. printf("Invoke(ConnectionMade) returned 0x%x\n", hr);
  329. if (FAILED(hr))
  330. {
  331. goto Cleanup;
  332. }
  333. //
  334. // Cleanup stuff
  335. //
  336. Cleanup:
  337. if (pIDispatchNetwork)
  338. {
  339. pIDispatchNetwork->Release();
  340. }
  341. if (pIDispatchLogon)
  342. {
  343. pIDispatchLogon->Release();
  344. }
  345. if (pISensNetwork)
  346. {
  347. pISensNetwork->Release();
  348. }
  349. if (pISensLogon)
  350. {
  351. pISensLogon->Release();
  352. }
  353. if (pITypeLib)
  354. {
  355. pITypeLib->Release();
  356. }
  357. if (pITypeInfo)
  358. {
  359. pITypeInfo->Release();
  360. }
  361. CoUninitialize();
  362. printf("--------------------------------------------------------------\n");
  363. return (SUCCEEDED(hr) ? 0 : -1);
  364. }