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.

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