Source code of Windows XP (NT5)
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.

2231 lines
49 KiB

  1. /*
  2. * client.cxx
  3. */
  4. #include "client.hxx"
  5. #define MIN_TEST_NUMBER 1
  6. #define MAX_TEST_NUMBER 27
  7. BOOL UnimplementedTest();
  8. BOOL UnsupportedTest();
  9. BOOL GenericCITest(REFCLSID clsid, REFIID iid, WCHAR * szServerName, int n, DWORD ctxt);
  10. BOOL CGCOLocalEXE();
  11. BOOL CGCOExplicitActivator();
  12. BOOL CILocalDLL();
  13. BOOL CILocalEXE();
  14. BOOL CIExplicitActivator();
  15. BOOL CI3LocalEXE();
  16. BOOL CI3ExplicitActivator();
  17. BOOL CGIFFLocalEXE();
  18. BOOL CGIFFExplicitActivator();
  19. BOOL CGIFFRegistryActivator();
  20. BOOL CGIFFAtStorageActivator();
  21. BOOL IMBLocalEXE();
  22. BOOL IMBLocalService();
  23. BOOL IMBAtStorageActivator();
  24. BOOL IMBAtStorageService();
  25. BOOL IMBAtStoragePreCon();
  26. BOOL IMBAtStorageUser();
  27. BOOL CIFromStgLocalEXE();
  28. BOOL CIFromStgActivator();
  29. BOOL CICustomLocalDLL();
  30. BOOL CICustomLocalEXE();
  31. BOOL CILocalPreCon();
  32. BOOL CIExplicitPreCon();
  33. BOOL CILocalUser();
  34. BOOL CIExplicitUser();
  35. BOOL CILocalPreConACL();
  36. BOOL CIExplicitPreConACL();
  37. BOOL CILocalService();
  38. BOOL CIExplicitService();
  39. BOOL MyStartService(WCHAR * wszServiceName, WCHAR *pwszRegServiceArgs);
  40. BOOL MyStopService(WCHAR * wszServiceName);
  41. #ifdef NO_DCOM
  42. LPTESTFUNC rgTest[] =
  43. {
  44. NULL,
  45. CGCOLocalEXE,
  46. UnsupportedTest,
  47. CILocalDLL,
  48. CILocalEXE,
  49. UnsupportedTest,
  50. UnsupportedTest,
  51. UnsupportedTest,
  52. UnsupportedTest,
  53. UnsupportedTest,
  54. UnsupportedTest,
  55. UnsupportedTest
  56. /* New tests
  57. UnsupportedTest,
  58. UnsupportedTest,
  59. end new tests */
  60. CI3LocalEXE,
  61. UnsupportedTest,
  62. UnsupportedTest,
  63. UnsupportedTest,
  64. UnsupportedTest,
  65. UnsupportedTest,
  66. UnsupportedTest,
  67. UnsupportedTest,
  68. IMBLocalEXE,
  69. UnsupportedTest,
  70. UnsupportedTest,
  71. UnsupportedTest,
  72. UnsupportedTest,
  73. UnsupportedTest,
  74. UnsupportedTest,
  75. UnsupportedTest,
  76. NULL
  77. };
  78. #else
  79. LPTESTFUNC rgTest[] =
  80. {
  81. NULL,
  82. CGCOLocalEXE,
  83. CGCOExplicitActivator,
  84. CILocalDLL,
  85. CILocalEXE,
  86. CIExplicitActivator,
  87. CILocalPreCon,
  88. CIExplicitPreCon,
  89. CILocalUser,
  90. CIExplicitUser,
  91. CILocalService,
  92. CIExplicitService,
  93. /* new tests
  94. CILocalPreConACL,
  95. CIExplicitPreConACL,
  96. end new tests */
  97. CI3LocalEXE,
  98. CI3ExplicitActivator,
  99. CICustomLocalDLL,
  100. CICustomLocalEXE,
  101. CGIFFLocalEXE,
  102. CGIFFExplicitActivator,
  103. CGIFFRegistryActivator,
  104. CGIFFAtStorageActivator,
  105. IMBLocalEXE,
  106. IMBLocalService,
  107. IMBAtStorageActivator,
  108. IMBAtStorageService,
  109. IMBAtStoragePreCon,
  110. IMBAtStorageUser,
  111. CIFromStgLocalEXE,
  112. CIFromStgActivator,
  113. NULL
  114. };
  115. #endif // NO_DCOM
  116. char * TestName[] =
  117. {
  118. NULL,
  119. "CoGetClassObject local EXE",
  120. "CoGetClassObject explicit activator",
  121. "CoCreateInstance local DLL",
  122. "CoCreateInstance local EXE",
  123. "CoCreateInstance explicit activator",
  124. "CoCreateInstance local pre-configured",
  125. "CoCreateInstance explicit pre-configured",
  126. "CoCreateInstance local user",
  127. "CoCreateInstance explicit user",
  128. "CoCreateInstance local service",
  129. "CoCreateInstance explicit service",
  130. /* new tests
  131. "CoCreateInstance local pre-configured ACL",
  132. "CoCreateInstance explicit pre-configured ACL",
  133. end new tests */
  134. "CoCreateInstance (3 IIDs) local EXE",
  135. "CoCreateInstance (3 IIDs) explicit activator",
  136. "CoCreateInstance from custom itf. local DLL",
  137. "CoCreateInstance from custom itf. local EXE",
  138. "CoGetInstanceFromFile local EXE",
  139. "CoGetInstanceFromFile explicit activator",
  140. "CoGetInstanceFromFile registry activator",
  141. "CoGetInstanceFromFile AtStorage activator",
  142. "IMoniker::BindToObject local EXE",
  143. "IMoniker::BindToObject local service",
  144. "IMoniker::BindToObject AtStorage activator",
  145. "IMoniker::BindToObject AtStorage service",
  146. "IMoniker::BindToObject AtStorage pre-configured",
  147. "IMoniker::BindToObject AtStorage user",
  148. "CoGetInstanceFromIStorage local EXE",
  149. "CoGetInstanceFromIStorage explicit activator",
  150. NULL
  151. };
  152. char RunTest[] =
  153. {
  154. -1,
  155. // CoGetClassObject
  156. YES,
  157. YES,
  158. // CoCreateInstance
  159. YES,
  160. YES,
  161. YES,
  162. YES,
  163. YES,
  164. YES,
  165. YES,
  166. YES,
  167. YES,
  168. /* new tests
  169. YES,
  170. YES,
  171. end new tests */
  172. // CoCreateInstance (3 IIDs)
  173. YES,
  174. YES,
  175. // CoGetInstanceFromFile
  176. YES,
  177. YES,
  178. YES,
  179. YES,
  180. // IMoniker:Bind
  181. YES,
  182. YES,
  183. YES,
  184. YES,
  185. YES,
  186. YES,
  187. YES,
  188. YES,
  189. YES,
  190. YES,
  191. -1
  192. };
  193. char RunLocalTest[] =
  194. {
  195. -1,
  196. // CoGetClassObject
  197. YES,
  198. NO,
  199. // CreateInstance
  200. YES,
  201. YES,
  202. NO,
  203. YES,
  204. NO,
  205. YES,
  206. NO,
  207. YES,
  208. NO,
  209. /* new tests
  210. YES,
  211. NO,
  212. end new tests */
  213. // CreateInstance (3 IIDs)
  214. YES,
  215. NO,
  216. // CreateInstance from custom Itf.
  217. YES,
  218. YES,
  219. // CoGetInstanceFromFile
  220. YES,
  221. NO,
  222. NO,
  223. NO,
  224. // IMoniker:Bind
  225. YES,
  226. YES,
  227. NO,
  228. NO,
  229. NO,
  230. NO,
  231. // CoGetInstanceFromIStorage
  232. YES,
  233. NO,
  234. -1
  235. };
  236. WCHAR ServerName[32];
  237. WCHAR RemoteFileName[256];
  238. WCHAR * LocalFileName = L"c:\\acttest.dat";
  239. WCHAR * StorageName = L"c:\\acttest.stg";
  240. LARGE_INTEGER liPerfFreq;
  241. LARGE_INTEGER liStart;
  242. LARGE_INTEGER liStop;
  243. LARGE_INTEGER liElapsedTime;
  244. #define RESET_CLOCK liElapsedTime.LowPart = liElapsedTime.HighPart = 0
  245. #define START_CLOCK QueryPerformanceCounter(&liStart)
  246. #define STOP_CLOCK QueryPerformanceCounter(&liStop); \
  247. liElapsedTime.QuadPart += liStop.QuadPart - liStart.QuadPart
  248. #define DUMP_CLOCK DisplayElapsedTime()
  249. #define START_LOOP for (unsigned sl_n = uIterations+1; sl_n--;){
  250. #define STOP_LOOP if (uIterations == sl_n ) RESET_CLOCK;}
  251. #define SLEEP_IF_LOOPING if (sl_n && !gfHoldServer) Sleep(1000)
  252. unsigned uIterations = 0;
  253. BOOL gfRegister = TRUE;
  254. BOOL gfHoldServer = FALSE;
  255. BOOL gfLocal = FALSE;
  256. BOOL gfNolocal = FALSE;
  257. BOOL gfSpecificTest = FALSE;
  258. DWORD dwWaitHint = 0;
  259. void DisplayElapsedTime(void)
  260. {
  261. LONGLONG MicroPerIter;
  262. liElapsedTime.QuadPart /= uIterations;
  263. MicroPerIter = liElapsedTime.QuadPart * 1000000;
  264. MicroPerIter /= liPerfFreq.QuadPart;
  265. printf( "Time: %d microseconds per iteration", (DWORD) MicroPerIter );
  266. }
  267. BOOL AllLocal()
  268. {
  269. for (int x = MIN_TEST_NUMBER; x<= MAX_TEST_NUMBER; x++)
  270. {
  271. if (RunTest[x] && !RunLocalTest[x])
  272. return(FALSE);
  273. }
  274. return(TRUE);
  275. }
  276. extern WCHAR ServiceName[];
  277. void _cdecl main( int argc, char ** argv )
  278. {
  279. HRESULT HResult;
  280. HANDLE hFile;
  281. int n;
  282. BOOL f;
  283. if (argc > 1)
  284. {
  285. if (argc == 3 && (!strcmp(argv[1], "-t")))
  286. {
  287. dwWaitHint = atoi(argv[2]);
  288. }
  289. else
  290. {
  291. printf("usage: %s [-t #]\n # number of milliseconds between QueryServiceStatus calls\n", argv[0]);
  292. return;
  293. }
  294. }
  295. if ((!QueryPerformanceFrequency(&liPerfFreq)) && uIterations > 0)
  296. {
  297. printf("No high performance counter.\nTests cannot be timed.\nAborting.\n");
  298. return;
  299. }
  300. uIterations = 1;
  301. printf("Starting service...\n");
  302. RESET_CLOCK;
  303. START_CLOCK;
  304. f = MyStartService(L"ActTestService", L"");
  305. STOP_CLOCK;
  306. if (f)
  307. printf("succeeded - ");
  308. else
  309. printf("failed - ");
  310. DUMP_CLOCK;
  311. printf("\n");
  312. printf("Stopping service...\n");
  313. RESET_CLOCK;
  314. START_CLOCK;
  315. f = MyStopService(L"ActTestService");
  316. STOP_CLOCK;
  317. if (f)
  318. printf("succeeded - ");
  319. else
  320. printf("failed - ");
  321. DUMP_CLOCK;
  322. printf("\n");
  323. return;
  324. #ifndef NO_DCOM
  325. if ( argc == 1 )
  326. PrintUsageAndExit( FALSE );
  327. #endif // NO_DCOM
  328. if ( argc > 1 && strcmp(argv[1],"-?") == 0 )
  329. PrintUsageAndExit( TRUE );
  330. n = 1;
  331. while ( (n < argc) && (*argv[n] == '-') )
  332. {
  333. if ( (n < argc) && strcmp(argv[n],"-local") == 0 )
  334. {
  335. if (gfLocal | gfNolocal)
  336. {
  337. PrintUsageAndExit( FALSE );
  338. }
  339. gfLocal = TRUE;
  340. memcpy(RunTest, RunLocalTest, MAX_TEST_NUMBER + MIN_TEST_NUMBER);
  341. n++;
  342. }
  343. if ( (n < argc) && strcmp(argv[n],"-nolocal") == 0 )
  344. {
  345. if (gfLocal | gfNolocal)
  346. {
  347. PrintUsageAndExit( FALSE );
  348. }
  349. gfNolocal = TRUE;
  350. for (int x = MIN_TEST_NUMBER; x<= MAX_TEST_NUMBER; x++)
  351. {
  352. RunTest[x] = !RunLocalTest[x];
  353. }
  354. n++;
  355. }
  356. if ( (n < argc) && strcmp(argv[n],"-noreg") == 0 )
  357. {
  358. gfRegister = FALSE;
  359. n++;
  360. continue;
  361. }
  362. if ( (n < argc) && strcmp(argv[n],"-hold") == 0 )
  363. {
  364. gfHoldServer = TRUE;
  365. n++;
  366. continue;
  367. }
  368. if ( (n < argc) && strcmp(argv[n],"-n") == 0 )
  369. {
  370. if ( ++n >= argc )
  371. PrintUsageAndExit(FALSE);
  372. uIterations = atoi(argv[n++]);
  373. }
  374. if ( (n < argc) && strcmp(argv[n],"-t") == 0 )
  375. {
  376. long TestNum1, TestNum2;
  377. if ( ++n >= argc )
  378. PrintUsageAndExit(FALSE);
  379. TestNum1 = atoi(argv[n++]);
  380. if ( (n < argc) && ((TestNum2 = atoi(argv[n])) != 0) )
  381. n++;
  382. else
  383. TestNum2 = TestNum1;
  384. if ( (TestNum1 < MIN_TEST_NUMBER) || (TestNum2 > MAX_TEST_NUMBER) )
  385. {
  386. printf( "Test number(s) must be between %d and %d.\n",
  387. MIN_TEST_NUMBER,
  388. MAX_TEST_NUMBER );
  389. return;
  390. }
  391. if ( TestNum1 > TestNum2 )
  392. {
  393. printf( "Second test number must be greater than the first.\n" );
  394. return;
  395. }
  396. if (!gfSpecificTest)
  397. {
  398. gfSpecificTest = TRUE;
  399. // only do this the first time -t is found on the command line
  400. memset(RunTest,NO,sizeof(RunTest));
  401. }
  402. memset(&RunTest[TestNum1],YES,sizeof(char)*(TestNum2-TestNum1+1));
  403. }
  404. }
  405. #ifndef NO_DCOM
  406. if ( n != argc - 1 && !AllLocal())
  407. {
  408. printf("ERROR - Selected tests require a server name.\n");
  409. ExitThread(0);
  410. }
  411. if ( n < argc )
  412. {
  413. MultiByteToWideChar( CP_ACP,
  414. 0,
  415. argv[n],
  416. -1,
  417. ServerName,
  418. sizeof(ServerName) / sizeof(WCHAR) );
  419. }
  420. else
  421. ServerName[0] = 0;
  422. #endif // NO_DCOM
  423. hFile = CreateFile(
  424. LocalFileName,
  425. GENERIC_WRITE,
  426. FILE_SHARE_READ,
  427. 0,
  428. OPEN_ALWAYS,
  429. FILE_ATTRIBUTE_NORMAL,
  430. 0 );
  431. if ( hFile == INVALID_HANDLE_VALUE )
  432. {
  433. printf("CreateFile failed while creating local file: %d\n", GetLastError());
  434. return;
  435. }
  436. CloseHandle( hFile );
  437. #ifndef NO_DCOM
  438. if ( ServerName[0] != 0 )
  439. {
  440. RemoteFileName[0] = 0;
  441. if ( ServerName[0] != L'\\' )
  442. wcscat( RemoteFileName, L"\\\\" );
  443. wcscat( RemoteFileName, ServerName );
  444. wcscat( RemoteFileName, L"\\c$\\acttest.dat" );
  445. hFile = CreateFile(
  446. RemoteFileName,
  447. GENERIC_WRITE,
  448. FILE_SHARE_READ,
  449. 0,
  450. OPEN_ALWAYS,
  451. FILE_ATTRIBUTE_NORMAL,
  452. 0 );
  453. if ( hFile == INVALID_HANDLE_VALUE )
  454. {
  455. printf("CreateFile failed while creating remote file: %d\n", GetLastError());
  456. return;
  457. }
  458. CloseHandle( hFile );
  459. }
  460. #endif // NO_DCOM
  461. HResult = CoInitialize(NULL);
  462. if( FAILED(HResult) )
  463. {
  464. printf( "Client CoInitialize failed Ox%x!\n", HResult );
  465. return;
  466. }
  467. if ((!QueryPerformanceFrequency(&liPerfFreq)) && uIterations > 0)
  468. {
  469. printf("No high performance counter.\nTests cannot be timed.\nAborting.\n");
  470. }
  471. else
  472. {
  473. if ( ! Tests() )
  474. printf("\nTests FAILED\n");
  475. else
  476. printf("\nTests SUCCEEDED\n");
  477. }
  478. CoUninitialize();
  479. DeleteFile( LocalFileName );
  480. #ifndef NO_DCOM
  481. DeleteFile( RemoteFileName );
  482. #endif // NO_DCOM
  483. }
  484. BOOL Tests()
  485. {
  486. HRESULT HResult;
  487. long RegStatus;
  488. if (gfRegister)
  489. {
  490. DeleteClsidKey( ClsidGoober32String );
  491. DeleteClsidKey( ClsidActLocalString );
  492. DeleteClsidKey( ClsidActRemoteString );
  493. DeleteClsidKey( ClsidActAtStorageString );
  494. DeleteClsidKey( ClsidActInprocString );
  495. DeleteClsidKey( ClsidActPreConfigString );
  496. DeleteClsidKey( ClsidActRunAsLoggedOnString );
  497. DeleteClsidKey( ClsidActServiceString );
  498. DeleteClsidKey( ClsidActServerOnlyString );
  499. if ( (RegStatus = InitializeRegistryForInproc()) != ERROR_SUCCESS )
  500. {
  501. printf("InitializeRegistryForInproc failed %d.\n", RegStatus);
  502. return FALSE;
  503. }
  504. if ( (RegStatus = InitializeRegistryForLocal()) != ERROR_SUCCESS )
  505. {
  506. printf("InitializeRegistryForLocal failed %d.\n", RegStatus);
  507. return FALSE;
  508. }
  509. if ( (RegStatus = InitializeRegistryForCustom()) != ERROR_SUCCESS )
  510. {
  511. printf("InitializeRegistryForCustom failed %d.\n", RegStatus);
  512. return FALSE;
  513. }
  514. #ifndef NO_DCOM
  515. if ( (RegStatus = InitializeRegistryForRemote()) != ERROR_SUCCESS )
  516. {
  517. printf("InitializeRegistryForRemote failed %d.\n", RegStatus);
  518. return FALSE;
  519. }
  520. if ( (RegStatus = InitializeRegistryForService()) != ERROR_SUCCESS )
  521. {
  522. printf("InitializeRegistryForService failed %d.\n", RegStatus);
  523. return FALSE;
  524. }
  525. #endif // NO_DCOM
  526. }
  527. BOOL fAllTests = TRUE;
  528. for (int x = MIN_TEST_NUMBER; x <= MAX_TEST_NUMBER; x++)
  529. {
  530. if (RunTest[x])
  531. {
  532. printf("\nTest %2d: %s\n",x, TestName[x]);
  533. // prime the system once to ensure the test is fully cached
  534. if (rgTest[x]())
  535. {
  536. printf("PASSED");
  537. if (uIterations)
  538. {
  539. printf(" - ");
  540. DUMP_CLOCK;
  541. }
  542. printf("\n");
  543. }
  544. else
  545. {
  546. printf("FAILED\n");
  547. fAllTests = FALSE;
  548. }
  549. }
  550. }
  551. return(fAllTests);
  552. }
  553. void PrintUsageAndExit( BOOL bListTests )
  554. {
  555. #ifdef NO_DCOM
  556. printf("Usage : %s [-hold] [-noreg] [-n #] [-t # [#]]\n", "actclt");
  557. printf("\t-n # : Run specific number of timed iterations (default is 0).\n");
  558. printf("\t-noreg : Don't update registry\n");
  559. printf("\t-t # : Run specific test number or a range of tests.\n");
  560. printf("\t-? : Print usage plus test descriptions.\n");
  561. #else
  562. printf("Usage : %s [-hold] [-noreg] [[-local] | [-nolocal]] [-n #] [-t # [#]] [server_name]\n", "actclt");
  563. printf("\t-hold : Hold the server up during all iterations.\n");
  564. printf("\t-local : Run only local activation tests.\n");
  565. printf("\t-n # : Run specific number of timed iterations (default is 0).\n");
  566. printf("\t-nolocal : Run only remote activation tests.\n");
  567. printf("\t-noreg : Don't update registry\n");
  568. printf("\t-t # : Run specific test number or a range of tests.\n");
  569. printf("\t-? : Print usage plus test descriptions.\n");
  570. #endif // NO_DCOM
  571. if ( bListTests )
  572. {
  573. long n;
  574. printf("\nTests :\n");
  575. printf("\t # Method Location Security\n");
  576. printf("\t-- ----------------------------------- ----------- --------------\n");
  577. for ( n = MIN_TEST_NUMBER; n <= MAX_TEST_NUMBER; n++ )
  578. {
  579. printf("\t%2d %s\n", n, TestName[n]);
  580. }
  581. }
  582. ExitThread(0);
  583. }
  584. void * __RPC_API
  585. MIDL_user_allocate(size_t len)
  586. {
  587. return malloc(len);
  588. }
  589. void __RPC_API
  590. MIDL_user_free(void * vp)
  591. {
  592. free(vp);
  593. }
  594. BOOL StampFileWithCLSID(WCHAR * szFilename, CLSID & clsid)
  595. {
  596. HRESULT hr;
  597. IStorage * pStg;
  598. hr = StgCreateDocfile(
  599. szFilename,
  600. STGM_READWRITE | STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
  601. 0,
  602. &pStg);
  603. if (FAILED (hr))
  604. {
  605. printf("StgCreateDocfile returned 0x%x\n", hr);
  606. return(FALSE);
  607. }
  608. hr = WriteClassStg(pStg, clsid);
  609. pStg->Release();
  610. if (FAILED (hr))
  611. {
  612. printf("WriteClassStg returned 0x%x\n", hr);
  613. return(FALSE);
  614. }
  615. return(TRUE);
  616. }
  617. //
  618. // Test Procedures:
  619. //
  620. BOOL UnimplementedTest()
  621. {
  622. printf("Not implemented at this time.\n");
  623. return(TRUE);
  624. }
  625. BOOL UnsupportedTest()
  626. {
  627. printf("Not supported by this version.\n");
  628. return(TRUE);
  629. }
  630. BOOL GenericCITest(REFCLSID clsid, REFIID iid, WCHAR * szServerName, int n, DWORD ctxt)
  631. {
  632. COSERVERINFO ServerInfo;
  633. COSERVERINFO *pServerInfo;
  634. IUnknown * punkHeld = NULL;
  635. if (szServerName)
  636. {
  637. memset( &ServerInfo, 0, sizeof(COSERVERINFO) );
  638. ServerInfo.pwszName = szServerName;
  639. pServerInfo = &ServerInfo;
  640. }
  641. else
  642. {
  643. pServerInfo = NULL;
  644. }
  645. MULTI_QI QIStruct[10];
  646. int x;
  647. HRESULT hr;
  648. BOOL fReturn = TRUE;
  649. START_LOOP;
  650. for (x = n; x--;)
  651. {
  652. QIStruct[x].pItf = NULL;
  653. QIStruct[x].pIID = (IID *) &iid;
  654. }
  655. START_CLOCK;
  656. hr = CoCreateInstanceEx(
  657. clsid,
  658. NULL,
  659. ctxt,
  660. pServerInfo,
  661. n,
  662. QIStruct);
  663. STOP_CLOCK;
  664. if ( FAILED(hr) )
  665. {
  666. printf("CoCreateInstanceEx returned 0x%x\n", hr);
  667. if (punkHeld)
  668. punkHeld->Release();
  669. return FALSE;
  670. }
  671. if (gfHoldServer && NULL == punkHeld && SUCCEEDED(QIStruct[0].hr))
  672. {
  673. punkHeld = QIStruct[0].pItf;
  674. punkHeld->AddRef();
  675. }
  676. for (x = 0; x < n; x++)
  677. {
  678. if (FAILED(QIStruct[x].hr))
  679. {
  680. printf("CoCreateInstanceEx returned 0x%x for interface %d\n",
  681. QIStruct[x].hr, x);
  682. fReturn = FALSE;
  683. }
  684. else
  685. QIStruct[x].pItf->Release();
  686. }
  687. if (!fReturn)
  688. {
  689. if (punkHeld)
  690. punkHeld->Release();
  691. return(fReturn);
  692. }
  693. STOP_LOOP;
  694. if (punkHeld)
  695. punkHeld->Release();
  696. return fReturn;
  697. }
  698. BOOL CGCOLocalEXE()
  699. {
  700. IClassFactory * pClassFactory;
  701. IUnknown * pUnknown;
  702. IUnknown * punkHeld = NULL;
  703. HRESULT hr;
  704. START_LOOP;
  705. START_CLOCK;
  706. hr = CoGetClassObject(
  707. CLSID_ActLocal,
  708. CLSCTX_LOCAL_SERVER,
  709. NULL,
  710. IID_IClassFactory,
  711. (void **) &pClassFactory );
  712. STOP_CLOCK;
  713. if ( FAILED(hr) )
  714. {
  715. printf("CoGetClassObject returned 0x%x\n", hr);
  716. if (punkHeld)
  717. punkHeld->Release();
  718. return FALSE;
  719. }
  720. hr = pClassFactory->CreateInstance( NULL,
  721. IID_IUnknown,
  722. (void **) &pUnknown );
  723. pClassFactory->Release();
  724. if ( FAILED(hr) )
  725. {
  726. printf("CreateInstance returned 0x%x\n", hr);
  727. if (punkHeld)
  728. punkHeld->Release();
  729. return FALSE;
  730. }
  731. if (gfHoldServer && NULL == punkHeld)
  732. {
  733. punkHeld = pUnknown;
  734. punkHeld->AddRef();
  735. }
  736. pUnknown->Release();
  737. STOP_LOOP;
  738. if (punkHeld)
  739. punkHeld->Release();
  740. return TRUE;
  741. }
  742. #ifndef NO_DCOM
  743. BOOL CGCOExplicitActivator()
  744. {
  745. COSERVERINFO ServerInfo;
  746. memset( &ServerInfo, 0, sizeof(COSERVERINFO) );
  747. ServerInfo.pwszName = ServerName;
  748. IClassFactory * pClassFactory;
  749. IUnknown * pUnknown;
  750. IUnknown * punkHeld = NULL;
  751. HRESULT hr;
  752. START_LOOP;
  753. START_CLOCK;
  754. hr = CoGetClassObject(
  755. CLSID_ActLocal,
  756. CLSCTX_REMOTE_SERVER,
  757. &ServerInfo,
  758. IID_IClassFactory,
  759. (void **) &pClassFactory );
  760. STOP_CLOCK;
  761. if ( FAILED(hr) )
  762. {
  763. printf("CoGetClassObject returned 0x%x\n", hr);
  764. if (punkHeld)
  765. punkHeld->Release();
  766. return FALSE;
  767. }
  768. hr = pClassFactory->CreateInstance( NULL,
  769. IID_IUnknown,
  770. (void **) &pUnknown );
  771. pClassFactory->Release();
  772. if ( FAILED(hr) )
  773. {
  774. printf("CreateInstance returned 0x%x\n", hr);
  775. if (punkHeld)
  776. punkHeld->Release();
  777. return FALSE;
  778. }
  779. if (gfHoldServer && NULL == punkHeld)
  780. {
  781. punkHeld = pUnknown;
  782. punkHeld->AddRef();
  783. }
  784. pUnknown->Release();
  785. STOP_LOOP;
  786. if (punkHeld)
  787. punkHeld->Release();
  788. return TRUE;
  789. }
  790. #endif // NO_DCOM
  791. #ifdef NO_DCOM
  792. BOOL CILocalDLL()
  793. {
  794. IUnknown * pUnknown;
  795. IUnknown * punkHeld = NULL;
  796. HRESULT hr;
  797. START_LOOP;
  798. START_CLOCK;
  799. hr = CoCreateInstance(
  800. CLSID_ActInproc,
  801. NULL,
  802. CLSCTX_INPROC_SERVER,
  803. IID_IUnknown,
  804. (void **) &pUnknown );
  805. STOP_CLOCK;
  806. if ( FAILED(hr) )
  807. {
  808. printf("CoCreateInstance returned 0x%x\n", hr);
  809. if (punkHeld)
  810. punkHeld->Release();
  811. return FALSE;
  812. }
  813. if (gfHoldServer && NULL == punkHeld)
  814. {
  815. punkHeld = pUnknown;
  816. punkHeld->AddRef();
  817. }
  818. pUnknown->Release();
  819. STOP_LOOP;
  820. if (punkHeld)
  821. punkHeld->Release();
  822. return TRUE;
  823. }
  824. BOOL CILocalEXE()
  825. {
  826. IUnknown * pUnknown;
  827. IUnknown * punkHeld = NULL;
  828. HRESULT hr;
  829. START_LOOP;
  830. START_CLOCK;
  831. hr = CoCreateInstance(
  832. CLSID_ActLocal,
  833. NULL,
  834. CLSCTX_LOCAL_SERVER,
  835. IID_IUnknown,
  836. (void **) &pUnknown );
  837. STOP_CLOCK;
  838. if ( FAILED(hr) )
  839. {
  840. printf("CoCreateInstance returned 0x%x\n", hr);
  841. if (punkHeld)
  842. punkHeld->Release();
  843. return FALSE;
  844. }
  845. if (gfHoldServer && NULL == punkHeld)
  846. {
  847. punkHeld = pUnknown;
  848. punkHeld->AddRef();
  849. }
  850. pUnknown->Release();
  851. STOP_LOOP;
  852. if (punkHeld)
  853. punkHeld->Release();
  854. return TRUE;
  855. }
  856. #else
  857. BOOL CILocalDLL()
  858. {
  859. return GenericCITest(CLSID_ActInproc, IID_IUnknown, NULL, 1, CLSCTX_INPROC_SERVER);
  860. }
  861. BOOL CILocalEXE()
  862. {
  863. return GenericCITest(CLSID_ActLocal, IID_IUnknown, NULL, 1, CLSCTX_LOCAL_SERVER);
  864. }
  865. BOOL CIExplicitActivator()
  866. {
  867. return GenericCITest(CLSID_ActLocal, IID_IUnknown, ServerName, 1, CLSCTX_REMOTE_SERVER);
  868. }
  869. #endif // NO_DCOM
  870. #ifdef NO_DCOM
  871. // Pre-DCOM version of CI3LocalEXE which calls CoCreateInstance
  872. // once followed by 2 calls to QueryInterface
  873. // instead of calling CoCreateInstanceEx.
  874. BOOL CI3LocalEXE()
  875. {
  876. IUnknown * pUnknown;
  877. IUnknwon * punkHeld = NULL;
  878. IPersist * pPersist;
  879. IPersistFile * pPersistFile;
  880. HRESULT hr;
  881. START_LOOP;
  882. START_CLOCK;
  883. hr = CoCreateInstance(
  884. CLSID_ActLocal,
  885. NULL,
  886. CLSCTX_LOCAL_SERVER,
  887. IID_IUnknown,
  888. (void **) &pUnknown );
  889. if ( FAILED(hr) )
  890. {
  891. printf("CoCreateInstance returned 0x%x\n", hr);
  892. if (punkHeld)
  893. punkHeld->Release();
  894. return FALSE;
  895. }
  896. if (gfHoldServer && NULL == punkHeld)
  897. {
  898. punkHeld = pUnknown;
  899. punkHeld->AddRef();
  900. }
  901. pUnknown->QueryInterface( IID_IPersist, (void **)&pPersist );
  902. pUnknown->QueryInterface( IID_IPersist, (void **)&pPersistFile );
  903. STOP_CLOCK;
  904. pUnknown->Release();
  905. pPersist->Release();
  906. pPersistFile->Release();
  907. STOP_LOOP;
  908. if (punkHeld)
  909. punkHeld->Release();
  910. return TRUE;
  911. }
  912. #else // NO_DCOM
  913. BOOL CI3LocalEXE()
  914. {
  915. return GenericCITest(CLSID_ActLocal, IID_IPersist, NULL, 3, CLSCTX_LOCAL_SERVER);
  916. /*
  917. MULTI_QI QIStruct[3];
  918. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  919. QIStruct[1].pIID = (IID *)&IID_IPersist;
  920. QIStruct[2].pIID = (IID *)&IID_IPersistFile;
  921. QIStruct[0].pItf = NULL;
  922. QIStruct[1].pItf = NULL;
  923. QIStruct[2].pItf = NULL;
  924. */
  925. }
  926. BOOL CI3ExplicitActivator()
  927. {
  928. return GenericCITest(CLSID_ActLocal, IID_IPersist, ServerName, 3, CLSCTX_REMOTE_SERVER);
  929. /*
  930. MULTI_QI QIStruct[3];
  931. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  932. QIStruct[1].pIID = (IID *)&IID_IPersist;
  933. QIStruct[2].pIID = (IID *)&IID_IPersistFile;
  934. QIStruct[0].pItf = NULL;
  935. QIStruct[1].pItf = NULL;
  936. QIStruct[2].pItf = NULL;
  937. */
  938. }
  939. BOOL CGIFFLocalEXE()
  940. {
  941. MULTI_QI QIStruct[1];
  942. IUnknown * punkHeld = NULL;
  943. START_LOOP;
  944. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  945. QIStruct[0].pItf = NULL;
  946. START_CLOCK;
  947. HRESULT HResult = CoGetInstanceFromFile(
  948. NULL,
  949. &CLSID_ActLocal,
  950. NULL,
  951. CLSCTX_LOCAL_SERVER,
  952. STGM_READWRITE,
  953. LocalFileName,
  954. 1,
  955. QIStruct );
  956. STOP_CLOCK;
  957. if ( FAILED(HResult) )
  958. {
  959. printf("CoGetInstanceFromFile returned 0x%x\n", HResult);
  960. if (punkHeld)
  961. punkHeld->Release();
  962. return FALSE;
  963. }
  964. if (gfHoldServer && NULL == punkHeld)
  965. {
  966. punkHeld = QIStruct[0].pItf;
  967. punkHeld->AddRef();
  968. }
  969. QIStruct[0].pItf->Release();
  970. STOP_LOOP;
  971. if (punkHeld)
  972. punkHeld->Release();
  973. return(TRUE);
  974. }
  975. BOOL CGIFFExplicitActivator()
  976. {
  977. COSERVERINFO ServerInfo;
  978. IUnknown * punkHeld = NULL;
  979. memset( &ServerInfo, 0, sizeof(COSERVERINFO) );
  980. ServerInfo.pwszName = ServerName;
  981. MULTI_QI QIStruct[1];
  982. START_LOOP;
  983. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  984. QIStruct[0].pItf = NULL;
  985. START_CLOCK;
  986. HRESULT HResult = CoGetInstanceFromFile(
  987. &ServerInfo,
  988. &CLSID_ActLocal,
  989. NULL,
  990. CLSCTX_REMOTE_SERVER,
  991. STGM_READWRITE,
  992. RemoteFileName,
  993. 1,
  994. QIStruct );
  995. STOP_CLOCK;
  996. if ( FAILED(HResult) )
  997. {
  998. printf("CoGetInstanceFromFile returned 0x%x\n", HResult);
  999. if (punkHeld)
  1000. punkHeld->Release();
  1001. return FALSE;
  1002. }
  1003. if (gfHoldServer && NULL == punkHeld)
  1004. {
  1005. punkHeld = QIStruct[0].pItf;
  1006. punkHeld->AddRef();
  1007. }
  1008. QIStruct[0].pItf->Release();
  1009. STOP_LOOP;
  1010. if (punkHeld)
  1011. punkHeld->Release();
  1012. return(TRUE);
  1013. }
  1014. BOOL CGIFFRegistryActivator()
  1015. {
  1016. MULTI_QI QIStruct[1];
  1017. IUnknown * punkHeld = NULL;
  1018. START_LOOP;
  1019. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  1020. QIStruct[0].pItf = NULL;
  1021. START_CLOCK;
  1022. HRESULT HResult = CoGetInstanceFromFile(
  1023. NULL,
  1024. &CLSID_ActRemote,
  1025. NULL,
  1026. CLSCTX_REMOTE_SERVER,
  1027. STGM_READWRITE,
  1028. RemoteFileName,
  1029. 1,
  1030. QIStruct );
  1031. STOP_CLOCK;
  1032. if ( FAILED(HResult) )
  1033. {
  1034. printf("CoGetInstanceFromFile returned 0x%x\n", HResult);
  1035. if (punkHeld)
  1036. punkHeld->Release();
  1037. return FALSE;
  1038. }
  1039. if (gfHoldServer && NULL == punkHeld)
  1040. {
  1041. punkHeld = QIStruct[0].pItf;
  1042. punkHeld->AddRef();
  1043. }
  1044. QIStruct[0].pItf->Release();
  1045. STOP_LOOP;
  1046. if (punkHeld)
  1047. punkHeld->Release();
  1048. return(TRUE);
  1049. }
  1050. BOOL CGIFFAtStorageActivator()
  1051. {
  1052. MULTI_QI QIStruct[1];
  1053. IUnknown * punkHeld = NULL;
  1054. START_LOOP;
  1055. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  1056. QIStruct[0].pItf = NULL;
  1057. START_CLOCK;
  1058. HRESULT HResult = CoGetInstanceFromFile(
  1059. NULL,
  1060. &CLSID_ActAtStorage,
  1061. NULL,
  1062. CLSCTX_REMOTE_SERVER,
  1063. STGM_READWRITE,
  1064. RemoteFileName,
  1065. 1,
  1066. QIStruct );
  1067. STOP_CLOCK;
  1068. if ( FAILED(HResult) )
  1069. {
  1070. printf("CoGetInstanceFromFile returned 0x%x\n", HResult);
  1071. if (punkHeld)
  1072. punkHeld->Release();
  1073. return FALSE;
  1074. }
  1075. if (gfHoldServer && NULL == punkHeld)
  1076. {
  1077. punkHeld = QIStruct[0].pItf;
  1078. punkHeld->AddRef();
  1079. }
  1080. QIStruct[0].pItf->Release();
  1081. STOP_LOOP;
  1082. if (punkHeld)
  1083. punkHeld->Release();
  1084. return(TRUE);
  1085. }
  1086. #endif // NO_DCOM
  1087. BOOL IMBLocalEXE()
  1088. {
  1089. IBindCtx * pBc;
  1090. IUnknown * pUnk;
  1091. IUnknown * punkHeld = NULL;
  1092. HRESULT hr;
  1093. IMoniker *pMon;
  1094. if (!StampFileWithCLSID(LocalFileName, CLSID_ActLocal))
  1095. {
  1096. return(FALSE);
  1097. }
  1098. hr = CreateFileMoniker(LocalFileName, &pMon);
  1099. if (FAILED(hr))
  1100. {
  1101. printf("CreateFileMoniker returned 0x%x\n", hr);
  1102. }
  1103. hr = CreateBindCtx(0, &pBc);
  1104. if (FAILED(hr))
  1105. {
  1106. printf("CreateBindCtx returned 0x%x\n", hr);
  1107. pMon->Release();
  1108. return(FALSE);
  1109. }
  1110. START_LOOP;
  1111. START_CLOCK;
  1112. hr = pMon->BindToObject(
  1113. pBc,
  1114. NULL,
  1115. IID_IUnknown,
  1116. (void **) &pUnk);
  1117. STOP_CLOCK;
  1118. if (FAILED(hr))
  1119. {
  1120. printf("IMoniker::BindToObject returned 0x%x\n", hr);
  1121. if (punkHeld)
  1122. punkHeld->Release();
  1123. return(FALSE);
  1124. }
  1125. if (gfHoldServer && NULL == punkHeld)
  1126. {
  1127. punkHeld = pUnk;
  1128. punkHeld->AddRef();
  1129. }
  1130. pUnk->Release();
  1131. STOP_LOOP
  1132. pMon->Release();
  1133. pBc->Release();
  1134. if (punkHeld)
  1135. punkHeld->Release();
  1136. return(TRUE);
  1137. }
  1138. #ifndef NO_DCOM
  1139. BOOL IMBLocalService()
  1140. {
  1141. IBindCtx * pBc;
  1142. IUnknown * pUnk;
  1143. IUnknown * punkHeld = NULL;
  1144. HRESULT hr;
  1145. IMoniker *pMon;
  1146. if (!StampFileWithCLSID(LocalFileName, CLSID_ActService))
  1147. {
  1148. return(FALSE);
  1149. }
  1150. hr = CreateFileMoniker(LocalFileName, &pMon);
  1151. if (FAILED(hr))
  1152. {
  1153. printf("CreateFileMoniker returned 0x%x\n", hr);
  1154. }
  1155. hr = CreateBindCtx(0, &pBc);
  1156. if (FAILED(hr))
  1157. {
  1158. printf("CreateBindCtx returned 0x%x\n", hr);
  1159. pMon->Release();
  1160. return(FALSE);
  1161. }
  1162. START_LOOP;
  1163. START_CLOCK;
  1164. hr = pMon->BindToObject(
  1165. pBc,
  1166. NULL,
  1167. IID_IUnknown,
  1168. (void **) &pUnk);
  1169. STOP_CLOCK;
  1170. if (FAILED(hr))
  1171. {
  1172. printf("IMoniker::BindToObject returned 0x%x\n", hr);
  1173. if (punkHeld)
  1174. punkHeld->Release();
  1175. return(FALSE);
  1176. }
  1177. if (gfHoldServer && NULL == punkHeld)
  1178. {
  1179. punkHeld = pUnk;
  1180. punkHeld->AddRef();
  1181. }
  1182. pUnk->Release();
  1183. SLEEP_IF_LOOPING;
  1184. STOP_LOOP;
  1185. pMon->Release();
  1186. pBc->Release();
  1187. if (punkHeld)
  1188. punkHeld->Release();
  1189. return(TRUE);
  1190. }
  1191. BOOL IMBAtStorageActivator()
  1192. {
  1193. IBindCtx * pBc;
  1194. IUnknown * pUnk;
  1195. IUnknown * punkHeld = NULL;
  1196. HRESULT hr;
  1197. IMoniker *pMon;
  1198. if (!StampFileWithCLSID(RemoteFileName, CLSID_ActAtStorage))
  1199. {
  1200. return(FALSE);
  1201. }
  1202. hr = CreateFileMoniker(RemoteFileName, &pMon);
  1203. if (FAILED(hr))
  1204. {
  1205. printf("CreateFileMoniker returned 0x%x\n", hr);
  1206. }
  1207. hr = CreateBindCtx(0, &pBc);
  1208. if (FAILED(hr))
  1209. {
  1210. printf("CreateBindCtx returned 0x%x\n", hr);
  1211. pMon->Release();
  1212. return(FALSE);
  1213. }
  1214. START_LOOP;
  1215. START_CLOCK;
  1216. hr = pMon->BindToObject(
  1217. pBc,
  1218. NULL,
  1219. IID_IUnknown,
  1220. (void **) &pUnk);
  1221. STOP_CLOCK;
  1222. if (FAILED(hr))
  1223. {
  1224. printf("IMoniker::BindToObject returned 0x%x\n", hr);
  1225. if (punkHeld)
  1226. punkHeld->Release();
  1227. return(FALSE);
  1228. }
  1229. if (gfHoldServer && NULL == punkHeld)
  1230. {
  1231. punkHeld = pUnk;
  1232. punkHeld->AddRef();
  1233. }
  1234. pUnk->Release();
  1235. STOP_LOOP;
  1236. pMon->Release();
  1237. pBc->Release();
  1238. if (punkHeld)
  1239. punkHeld->Release();
  1240. return(TRUE);
  1241. }
  1242. BOOL IMBAtStorageService()
  1243. {
  1244. IBindCtx * pBc;
  1245. IUnknown * pUnk;
  1246. IUnknown * punkHeld = NULL;
  1247. HRESULT hr;
  1248. IMoniker *pMon;
  1249. if (!StampFileWithCLSID(RemoteFileName, CLSID_ActService))
  1250. {
  1251. return(FALSE);
  1252. }
  1253. hr = CreateFileMoniker(RemoteFileName, &pMon);
  1254. if (FAILED(hr))
  1255. {
  1256. printf("CreateFileMoniker returned 0x%x\n", hr);
  1257. }
  1258. hr = CreateBindCtx(0, &pBc);
  1259. if (FAILED(hr))
  1260. {
  1261. printf("CreateBindCtx returned 0x%x\n", hr);
  1262. pMon->Release();
  1263. return(FALSE);
  1264. }
  1265. START_LOOP;
  1266. START_CLOCK;
  1267. hr = pMon->BindToObject(
  1268. pBc,
  1269. NULL,
  1270. IID_IUnknown,
  1271. (void **) &pUnk);
  1272. STOP_CLOCK;
  1273. if (FAILED(hr))
  1274. {
  1275. printf("IMoniker::BindToObject returned 0x%x\n", hr);
  1276. if (punkHeld)
  1277. punkHeld->Release();
  1278. return(FALSE);
  1279. }
  1280. if (gfHoldServer && NULL == punkHeld)
  1281. {
  1282. punkHeld = pUnk;
  1283. punkHeld->AddRef();
  1284. }
  1285. pUnk->Release();
  1286. SLEEP_IF_LOOPING;
  1287. STOP_LOOP;
  1288. pMon->Release();
  1289. pBc->Release();
  1290. if (punkHeld)
  1291. punkHeld->Release();
  1292. return(TRUE);
  1293. }
  1294. BOOL IMBAtStoragePreCon()
  1295. {
  1296. IBindCtx * pBc;
  1297. IUnknown * pUnk;
  1298. IUnknown * punkHeld = NULL;
  1299. HRESULT hr;
  1300. IMoniker *pMon;
  1301. if (!StampFileWithCLSID(RemoteFileName, CLSID_ActPreConfig))
  1302. {
  1303. return(FALSE);
  1304. }
  1305. hr = CreateFileMoniker(RemoteFileName, &pMon);
  1306. if (FAILED(hr))
  1307. {
  1308. printf("CreateFileMoniker returned 0x%x\n", hr);
  1309. }
  1310. hr = CreateBindCtx(0, &pBc);
  1311. if (FAILED(hr))
  1312. {
  1313. printf("CreateBindCtx returned 0x%x\n", hr);
  1314. pMon->Release();
  1315. return(FALSE);
  1316. }
  1317. START_LOOP;
  1318. START_CLOCK;
  1319. hr = pMon->BindToObject(
  1320. pBc,
  1321. NULL,
  1322. IID_IUnknown,
  1323. (void **) &pUnk);
  1324. STOP_CLOCK;
  1325. if (FAILED(hr))
  1326. {
  1327. printf("IMoniker::BindToObject returned 0x%x\n", hr);
  1328. if (punkHeld)
  1329. punkHeld->Release();
  1330. return(FALSE);
  1331. }
  1332. if (gfHoldServer && NULL == punkHeld)
  1333. {
  1334. punkHeld = pUnk;
  1335. punkHeld->AddRef();
  1336. }
  1337. pUnk->Release();
  1338. STOP_LOOP;
  1339. pMon->Release();
  1340. pBc->Release();
  1341. if (punkHeld)
  1342. punkHeld->Release();
  1343. return(TRUE);
  1344. }
  1345. BOOL IMBAtStorageUser()
  1346. {
  1347. IBindCtx * pBc;
  1348. IUnknown * pUnk;
  1349. IUnknown * punkHeld = NULL;
  1350. HRESULT hr;
  1351. IMoniker *pMon;
  1352. if (!StampFileWithCLSID(RemoteFileName, CLSID_ActRunAsLoggedOn))
  1353. {
  1354. return(FALSE);
  1355. }
  1356. hr = CreateFileMoniker(RemoteFileName, &pMon);
  1357. if (FAILED(hr))
  1358. {
  1359. printf("CreateFileMoniker returned 0x%x\n", hr);
  1360. }
  1361. hr = CreateBindCtx(0, &pBc);
  1362. if (FAILED(hr))
  1363. {
  1364. printf("CreateBindCtx returned 0x%x\n", hr);
  1365. pMon->Release();
  1366. return(FALSE);
  1367. }
  1368. START_LOOP;
  1369. START_CLOCK;
  1370. hr = pMon->BindToObject(
  1371. pBc,
  1372. NULL,
  1373. IID_IUnknown,
  1374. (void **) &pUnk);
  1375. STOP_CLOCK;
  1376. if (FAILED(hr))
  1377. {
  1378. printf("IMoniker::BindToObject returned 0x%x\n", hr);
  1379. if (punkHeld)
  1380. punkHeld->Release();
  1381. return(FALSE);
  1382. }
  1383. if (gfHoldServer && NULL == punkHeld)
  1384. {
  1385. punkHeld = pUnk;
  1386. punkHeld->AddRef();
  1387. }
  1388. pUnk->Release();
  1389. STOP_LOOP;
  1390. pMon->Release();
  1391. pBc->Release();
  1392. if (punkHeld)
  1393. punkHeld->Release();
  1394. return(TRUE);
  1395. }
  1396. BOOL CIFromStgLocalEXE()
  1397. {
  1398. IStorage * pStorage;
  1399. MULTI_QI QIStruct[10];
  1400. IUnknown * punkHeld = NULL;
  1401. pStorage = 0;
  1402. DeleteFile( StorageName );
  1403. HRESULT HResult = StgCreateDocfile(
  1404. StorageName,
  1405. STGM_READWRITE | STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
  1406. 0,
  1407. &pStorage );
  1408. if ( FAILED(HResult) )
  1409. {
  1410. printf("StgCreateDocfile returned 0x%x\n", HResult);
  1411. return FALSE;
  1412. }
  1413. START_LOOP;
  1414. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  1415. QIStruct[0].pItf = NULL;
  1416. START_CLOCK;
  1417. HResult = CoGetInstanceFromIStorage(
  1418. NULL,
  1419. &CLSID_ActLocal,
  1420. NULL,
  1421. CLSCTX_SERVER,
  1422. pStorage,
  1423. 1,
  1424. QIStruct );
  1425. STOP_CLOCK;
  1426. if ( FAILED(HResult) )
  1427. {
  1428. printf("CoGetInstanceFromIStorage returned 0x%x\n", HResult);
  1429. if (punkHeld)
  1430. punkHeld->Release();
  1431. return FALSE;
  1432. }
  1433. if (gfHoldServer && NULL == punkHeld)
  1434. {
  1435. punkHeld = QIStruct[0].pItf;
  1436. punkHeld->AddRef();
  1437. }
  1438. QIStruct[0].pItf->Release();
  1439. QIStruct[0].pItf = 0;
  1440. STOP_LOOP;
  1441. pStorage->Release();
  1442. if (punkHeld)
  1443. punkHeld->Release();
  1444. return(TRUE);
  1445. }
  1446. BOOL CIFromStgActivator()
  1447. {
  1448. IStorage * pStorage;
  1449. MULTI_QI QIStruct[10];
  1450. COSERVERINFO ServerInfo;
  1451. IUnknown * punkHeld = NULL;
  1452. memset( &ServerInfo, 0, sizeof(COSERVERINFO) );
  1453. ServerInfo.pwszName = ServerName;
  1454. pStorage = 0;
  1455. DeleteFile( StorageName );
  1456. HRESULT HResult = StgCreateDocfile(
  1457. StorageName,
  1458. STGM_READWRITE | STGM_DIRECT | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
  1459. 0,
  1460. &pStorage );
  1461. if ( FAILED(HResult) )
  1462. {
  1463. printf("StgCreateDocfile returned 0x%x\n", HResult);
  1464. return FALSE;
  1465. }
  1466. START_LOOP;
  1467. QIStruct[0].pIID = (IID *)&IID_IUnknown;
  1468. QIStruct[0].pItf = NULL;
  1469. START_CLOCK;
  1470. HResult = CoGetInstanceFromIStorage(
  1471. &ServerInfo,
  1472. &CLSID_ActRemote,
  1473. NULL,
  1474. CLSCTX_REMOTE_SERVER,
  1475. pStorage,
  1476. 1,
  1477. QIStruct );
  1478. STOP_CLOCK;
  1479. if ( FAILED(HResult) )
  1480. {
  1481. printf("CoGetInstanceFromIStorage returned 0x%x\n", HResult);
  1482. if (punkHeld)
  1483. punkHeld->Release();
  1484. return FALSE;
  1485. }
  1486. if (gfHoldServer && NULL == punkHeld)
  1487. {
  1488. punkHeld = QIStruct[0].pItf;
  1489. punkHeld->AddRef();
  1490. }
  1491. QIStruct[0].pItf->Release();
  1492. QIStruct[0].pItf = 0;
  1493. STOP_LOOP;
  1494. pStorage->Release();
  1495. if (punkHeld)
  1496. punkHeld->Release();
  1497. return(TRUE);
  1498. }
  1499. BOOL CICustomLocalDLL()
  1500. {
  1501. IGoober * pGoober;
  1502. MULTI_QI QIStruct[10];
  1503. HRESULT hr;
  1504. IUnknown * punkHeld = NULL;
  1505. START_LOOP;
  1506. QIStruct[0].pItf = NULL;
  1507. QIStruct[0].pIID = (IID *) &IID_IGoober;
  1508. START_CLOCK;
  1509. hr = CoCreateInstanceEx(
  1510. CLSID_ActInproc,
  1511. NULL,
  1512. CLSCTX_INPROC_SERVER,
  1513. NULL,
  1514. 1,
  1515. QIStruct );
  1516. STOP_CLOCK;
  1517. pGoober = (IGoober *)QIStruct[0].pItf;
  1518. if ( FAILED(hr) )
  1519. {
  1520. printf("CoCreateInstanceEx returned 0x%x\n", hr);
  1521. if (punkHeld)
  1522. punkHeld->Release();
  1523. return FALSE;
  1524. }
  1525. if (gfHoldServer && NULL == punkHeld)
  1526. {
  1527. punkHeld = QIStruct[0].pItf;
  1528. punkHeld->AddRef();
  1529. }
  1530. START_CLOCK;
  1531. hr = pGoober->Ping();
  1532. STOP_CLOCK;
  1533. if ( hr != S_OK )
  1534. {
  1535. printf("IGoober::Ping returned %d\n", hr);
  1536. pGoober->Release();
  1537. if (punkHeld)
  1538. punkHeld->Release();
  1539. return FALSE;
  1540. }
  1541. pGoober->Release();
  1542. STOP_LOOP;
  1543. if (punkHeld)
  1544. punkHeld->Release();
  1545. return(TRUE);
  1546. }
  1547. BOOL CICustomLocalEXE()
  1548. {
  1549. IGoober * pGoober;
  1550. MULTI_QI QIStruct[10];
  1551. HRESULT hr;
  1552. IUnknown * punkHeld = NULL;
  1553. START_LOOP;
  1554. QIStruct[0].pItf = NULL;
  1555. QIStruct[0].pIID = (IID *) &IID_IGoober;
  1556. START_CLOCK;
  1557. hr = CoCreateInstanceEx(
  1558. CLSID_ActLocal,
  1559. NULL,
  1560. CLSCTX_LOCAL_SERVER,
  1561. NULL,
  1562. 1,
  1563. QIStruct );
  1564. STOP_CLOCK;
  1565. pGoober = (IGoober *)QIStruct[0].pItf;
  1566. if ( FAILED(hr) )
  1567. {
  1568. printf("CoCreateInstanceEx returned 0x%x\n", hr);
  1569. if (punkHeld)
  1570. punkHeld->Release();
  1571. return FALSE;
  1572. }
  1573. if (gfHoldServer && NULL == punkHeld)
  1574. {
  1575. punkHeld = QIStruct[0].pItf;
  1576. punkHeld->AddRef();
  1577. }
  1578. START_CLOCK;
  1579. hr = pGoober->Ping();
  1580. STOP_CLOCK;
  1581. if ( hr != S_OK )
  1582. {
  1583. printf("IGoober::Ping returned %d\n", hr);
  1584. pGoober->Release();
  1585. if (punkHeld)
  1586. punkHeld->Release();
  1587. return FALSE;
  1588. }
  1589. pGoober->Release();
  1590. STOP_LOOP;
  1591. if (punkHeld)
  1592. punkHeld->Release();
  1593. return(TRUE);
  1594. }
  1595. BOOL CILocalPreCon()
  1596. {
  1597. return GenericCITest(CLSID_ActPreConfig, IID_IUnknown, NULL, 1, CLSCTX_LOCAL_SERVER);
  1598. }
  1599. BOOL CIExplicitPreCon()
  1600. {
  1601. return GenericCITest(CLSID_ActPreConfig, IID_IUnknown, ServerName, 1, CLSCTX_REMOTE_SERVER);
  1602. }
  1603. BOOL CILocalUser()
  1604. {
  1605. return GenericCITest(CLSID_ActRunAsLoggedOn, IID_IUnknown, NULL, 1, CLSCTX_LOCAL_SERVER);
  1606. }
  1607. BOOL CIExplicitUser()
  1608. {
  1609. return GenericCITest(CLSID_ActRunAsLoggedOn, IID_IUnknown, ServerName, 1, CLSCTX_REMOTE_SERVER);
  1610. }
  1611. BOOL CILocalService()
  1612. {
  1613. COSERVERINFO ServerInfo;
  1614. COSERVERINFO *pServerInfo;
  1615. IUnknown * punkHeld = NULL;
  1616. MULTI_QI QIStruct[1];
  1617. HRESULT hr;
  1618. BOOL fReturn = TRUE;
  1619. START_LOOP;
  1620. QIStruct[0].pItf = NULL;
  1621. QIStruct[0].pIID = (IID *) &IID_IUnknown;
  1622. START_CLOCK;
  1623. hr = CoCreateInstanceEx(
  1624. CLSID_ActService,
  1625. NULL,
  1626. CLSCTX_LOCAL_SERVER,
  1627. NULL,
  1628. 1,
  1629. QIStruct);
  1630. STOP_CLOCK;
  1631. if ( FAILED(hr) )
  1632. {
  1633. printf("CoCreateInstanceEx returned 0x%x\n", hr);
  1634. if (punkHeld)
  1635. punkHeld->Release();
  1636. return FALSE;
  1637. }
  1638. if (gfHoldServer && NULL == punkHeld && SUCCEEDED(QIStruct[0].hr))
  1639. {
  1640. punkHeld = QIStruct[0].pItf;
  1641. punkHeld->AddRef();
  1642. }
  1643. if (FAILED(QIStruct[0].hr))
  1644. {
  1645. printf("CoCreateInstanceEx returned 0x%x\n",
  1646. QIStruct[0].hr);
  1647. fReturn = FALSE;
  1648. }
  1649. else
  1650. QIStruct[0].pItf->Release();
  1651. if (!fReturn)
  1652. {
  1653. if (punkHeld)
  1654. punkHeld->Release();
  1655. return(fReturn);
  1656. }
  1657. SLEEP_IF_LOOPING;
  1658. STOP_LOOP;
  1659. if (punkHeld)
  1660. punkHeld->Release();
  1661. return fReturn;
  1662. }
  1663. BOOL CIExplicitService()
  1664. {
  1665. COSERVERINFO ServerInfo;
  1666. COSERVERINFO *pServerInfo;
  1667. IUnknown * punkHeld = NULL;
  1668. memset( &ServerInfo, 0, sizeof(COSERVERINFO) );
  1669. ServerInfo.pwszName = ServerName;
  1670. pServerInfo = &ServerInfo;
  1671. MULTI_QI QIStruct[1];
  1672. HRESULT hr;
  1673. BOOL fReturn = TRUE;
  1674. START_LOOP;
  1675. QIStruct[0].pItf = NULL;
  1676. QIStruct[0].pIID = (IID *) &IID_IUnknown;
  1677. START_CLOCK;
  1678. hr = CoCreateInstanceEx(
  1679. CLSID_ActService,
  1680. NULL,
  1681. CLSCTX_REMOTE_SERVER,
  1682. pServerInfo,
  1683. 1,
  1684. QIStruct);
  1685. STOP_CLOCK;
  1686. if ( FAILED(hr) )
  1687. {
  1688. printf("CoCreateInstanceEx returned 0x%x\n", hr);
  1689. if (punkHeld)
  1690. punkHeld->Release();
  1691. return FALSE;
  1692. }
  1693. if (gfHoldServer && NULL == punkHeld && SUCCEEDED(QIStruct[0].hr))
  1694. {
  1695. punkHeld = QIStruct[0].pItf;
  1696. punkHeld->AddRef();
  1697. }
  1698. if (FAILED(QIStruct[0].hr))
  1699. {
  1700. printf("CoCreateInstanceEx returned 0x%x\n",
  1701. QIStruct[0].hr);
  1702. fReturn = FALSE;
  1703. }
  1704. else
  1705. QIStruct[0].pItf->Release();
  1706. if (!fReturn)
  1707. {
  1708. if (punkHeld)
  1709. punkHeld->Release();
  1710. return(fReturn);
  1711. }
  1712. SLEEP_IF_LOOPING;
  1713. STOP_LOOP;
  1714. if (punkHeld)
  1715. punkHeld->Release();
  1716. return fReturn;
  1717. }
  1718. BOOL CILocalPreConACL();
  1719. BOOL CIExplicitPreConACL();
  1720. #define MAX_SERVICE_ARGS 10
  1721. BOOL MyStartService(WCHAR * wszServiceName, WCHAR *pwszRegServiceArgs)
  1722. {
  1723. SC_HANDLE hSCManager;
  1724. SC_HANDLE hService;
  1725. WCHAR *pwszServiceArgs = NULL;
  1726. ULONG cArgs = 0;
  1727. WCHAR *apwszArgs[MAX_SERVICE_ARGS];
  1728. // Get a handle to the Service Control Manager
  1729. if (hSCManager = OpenSCManager(NULL, NULL, GENERIC_EXECUTE | SERVICE_QUERY_STATUS ))
  1730. {
  1731. // Open a handle to the requested service
  1732. if (hService = OpenService(hSCManager, wszServiceName, GENERIC_EXECUTE | SERVICE_QUERY_STATUS ))
  1733. {
  1734. // Close the service manager's database
  1735. CloseServiceHandle(hSCManager);
  1736. // Formulate the arguments (if any)
  1737. if (pwszRegServiceArgs)
  1738. {
  1739. UINT k = 0;
  1740. // Make a copy of the service arguments
  1741. pwszServiceArgs = new WCHAR[(lstrlenW(pwszRegServiceArgs) + 1)];
  1742. if (pwszServiceArgs == NULL)
  1743. {
  1744. CloseServiceHandle(hService);
  1745. return FALSE;
  1746. }
  1747. lstrcpyW(pwszServiceArgs, pwszRegServiceArgs);
  1748. // Scan the arguments
  1749. do
  1750. {
  1751. // Scan to the next non-whitespace character
  1752. while(pwszServiceArgs[k] &&
  1753. (pwszServiceArgs[k] == L' ' ||
  1754. pwszServiceArgs[k] == L'\t'))
  1755. {
  1756. k++;
  1757. }
  1758. // Store the next argument
  1759. if (pwszServiceArgs[k])
  1760. {
  1761. apwszArgs[cArgs++] = &pwszServiceArgs[k];
  1762. }
  1763. // Scan to the next whitespace char
  1764. while(pwszServiceArgs[k] &&
  1765. pwszServiceArgs[k] != L' ' &&
  1766. pwszServiceArgs[k] != L'\t')
  1767. {
  1768. k++;
  1769. }
  1770. // Null terminate the previous argument
  1771. if (pwszServiceArgs[k])
  1772. {
  1773. pwszServiceArgs[k++] = L'\0';
  1774. }
  1775. } while(pwszServiceArgs[k]);
  1776. }
  1777. // Start the service
  1778. if (StartService(hService, cArgs,
  1779. cArgs > 0 ? (LPCTSTR *) apwszArgs : NULL))
  1780. {
  1781. SERVICE_STATUS ss;
  1782. do
  1783. {
  1784. QueryServiceStatus(hService, &ss);
  1785. if (dwWaitHint)
  1786. {
  1787. Sleep(dwWaitHint);
  1788. }
  1789. else
  1790. Sleep(ss.dwWaitHint);
  1791. } while (ss.dwCurrentState == SERVICE_START_PENDING);
  1792. CloseServiceHandle(hService);
  1793. delete [] pwszServiceArgs;
  1794. return TRUE;
  1795. }
  1796. else
  1797. {
  1798. CloseServiceHandle(hService);
  1799. delete [] pwszServiceArgs;
  1800. }
  1801. }
  1802. else
  1803. {
  1804. CloseServiceHandle(hSCManager);
  1805. }
  1806. }
  1807. DWORD err = GetLastError();
  1808. return FALSE;
  1809. }
  1810. BOOL MyStopService(WCHAR * wszServiceName)
  1811. {
  1812. SC_HANDLE hSCManager;
  1813. SC_HANDLE hService;
  1814. SERVICE_STATUS ss;
  1815. // Get a handle to the Service Control Manager
  1816. if (hSCManager = OpenSCManager(NULL, NULL, GENERIC_EXECUTE | SERVICE_QUERY_STATUS ))
  1817. {
  1818. // Open a handle to the requested service
  1819. if (hService = OpenService(hSCManager, wszServiceName, GENERIC_EXECUTE | SERVICE_QUERY_STATUS ))
  1820. {
  1821. // Close the service manager's database
  1822. CloseServiceHandle(hSCManager);
  1823. // Stop the service
  1824. if (ControlService(hService, SERVICE_CONTROL_STOP, &ss))
  1825. {
  1826. while (ss.dwCurrentState == SERVICE_STOP_PENDING)
  1827. {
  1828. if (dwWaitHint)
  1829. {
  1830. Sleep(dwWaitHint);
  1831. }
  1832. else
  1833. Sleep(ss.dwWaitHint);
  1834. QueryServiceStatus(hService, &ss);
  1835. };
  1836. CloseServiceHandle(hService);
  1837. return TRUE;
  1838. }
  1839. else
  1840. {
  1841. CloseServiceHandle(hService);
  1842. }
  1843. }
  1844. else
  1845. {
  1846. CloseServiceHandle(hSCManager);
  1847. }
  1848. }
  1849. DWORD err = GetLastError();
  1850. return FALSE;
  1851. }
  1852. #endif // NO_DCOM