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.

1041 lines
23 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1998
  6. //
  7. // File: csti.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. /*****************************************************************************
  11. csti.cpp
  12. History:
  13. vlads 02/01/97
  14. *****************************************************************************/
  15. // ##define _X86_ 1
  16. #define WIN32_LEAN_AND_MEAN 1
  17. #define INITGUID
  18. #include <windows.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <conio.h>
  22. #include <sti.h>
  23. #include <stireg.h>
  24. //#include <scanner.h>
  25. // {AD879F40-0982-11d1-A43B-080009EEBDF6}
  26. DEFINE_GUID( guidGreenButton, 0xad879f40, 0x982, 0x11d1, 0xa4, 0x3b, 0x8, 0x0, 0x9, 0xee, 0xbd, 0xf6 );
  27. #define USE_GETSTATUS
  28. /*****************************************************************************
  29. globals
  30. *****************************************************************************/
  31. PSTIA g_pSti = NULL;
  32. PSTIW g_pStiW = NULL;
  33. PSTIDEVICE g_pStiDevice = NULL;
  34. PSTIDEVICE g_pStiDevice1 = NULL;
  35. CHAR SCLReset[]= "E";
  36. CHAR SetXRes[] = "*a150R";
  37. CHAR InqXRes[] = "*s10323R";
  38. CHAR ScanCmd[] = "*f0S";
  39. CHAR LampOn[] = "*f1L";
  40. CHAR LampOff[] = "*f0L";
  41. CHAR PollButton[] = "*s1044E";
  42. TCHAR szSelectedDevice[STI_MAX_INTERNAL_NAME_LENGTH] = {L'\0'};
  43. BOOL g_fWait = FALSE;
  44. BOOL g_fTestSCL = FALSE;
  45. BOOL g_fTestEDNotifications = FALSE;
  46. BOOL g_fTestLaunchAPI = FALSE;
  47. BOOL g_fTestSetGetValue = FALSE;
  48. BOOL g_fTestRefreshAPI = TRUE;
  49. /*****************************************************************************
  50. prototypes
  51. *****************************************************************************/
  52. INT __cdecl main( INT cArgs,
  53. char * pArgs[] );
  54. HRESULT WINAPI
  55. SendDeviceCommandString(
  56. PSTIDEVICE pStiDevice,
  57. LPSTR pszFormat,
  58. ...);
  59. HRESULT WINAPI
  60. TransactDevice(
  61. PSTIDEVICE pStiDevice,
  62. LPSTR lpResultBuffer,
  63. UINT cbResultBufferSize,
  64. LPSTR pszFormat,
  65. ...);
  66. VOID
  67. TestEnumerationAndSelect(
  68. BOOL fMakeSelection
  69. );
  70. VOID
  71. TestQueryCustomInterface(
  72. LPTSTR pszDeviceName
  73. );
  74. VOID
  75. TestGetSetValue(
  76. LPTSTR pszDeviceName
  77. );
  78. BOOL
  79. TestStiLaunch(
  80. BOOL fRegister
  81. );
  82. VOID
  83. TestSCL(
  84. VOID
  85. );
  86. VOID
  87. TestWaitForNotifications(
  88. VOID
  89. );
  90. VOID
  91. TestEnableDisableNotifications(
  92. LPTSTR pszDeviceName
  93. );
  94. VOID
  95. TestLaunchAPI(
  96. LPTSTR pszDeviceName
  97. );
  98. VOID
  99. TestRefreshAPI(
  100. LPTSTR pszDeviceName
  101. );
  102. BOOL WINAPI
  103. FormatStringV(
  104. IN LPTSTR lpszStr,
  105. //LPSTR lpszFirst,
  106. ...
  107. );
  108. VOID
  109. ProcessCommandLine(
  110. INT cArgs,
  111. char * pArgs[]
  112. );
  113. /*****************************************************************************
  114. main
  115. *****************************************************************************/
  116. INT __cdecl main( INT cArgs,
  117. char * pArgs[] )
  118. {
  119. HRESULT hres;
  120. LPTSTR pszDeviceName = NULL;
  121. BOOL fAutoLaunched = FALSE;
  122. DWORD dwMode = STI_DEVICE_CREATE_STATUS;
  123. //
  124. // Startup stuff
  125. //
  126. printf("CSTI: Console mode test application for still image interface \n");
  127. OSVERSIONINFO OsVer;
  128. OsVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  129. GetVersionEx(&OsVer);
  130. printf(" Running on operating system version: \n Platform = %d \t Major=%d \t Minor=%d \n",
  131. OsVer.dwPlatformId,OsVer.dwMajorVersion,OsVer.dwMinorVersion);
  132. ProcessCommandLine( cArgs,pArgs ) ;
  133. //
  134. // Request STI interface pointer
  135. //
  136. hres = StiCreateInstanceA(GetModuleHandle(NULL), STI_VERSION, &g_pSti,NULL);
  137. if (!SUCCEEDED(hres) ) {
  138. printf("CSTI: StiCreateInstance Returned result=%x \n",hres);
  139. exit(0);
  140. }
  141. g_pSti->WriteToErrorLog(STI_TRACE_INFORMATION,"CSTI application started");
  142. //
  143. // Test custom global interface
  144. //
  145. hres = g_pSti->QueryInterface(IID_IStillImageW,(LPVOID *)&g_pStiW);
  146. if (SUCCEEDED(hres) && g_pStiW) {
  147. g_pStiW->WriteToErrorLog(STI_TRACE_INFORMATION,L"(UNICODE) CSTI application started");
  148. g_pStiW->Release();
  149. }
  150. fAutoLaunched = TestStiLaunch(TRUE);
  151. //
  152. // Test enumeration and select device
  153. //
  154. TestEnumerationAndSelect(fAutoLaunched ? FALSE : TRUE);
  155. if (*szSelectedDevice == L'\0') {
  156. printf("Device not selected, can not continue");
  157. goto Cleanup;
  158. }
  159. pszDeviceName = szSelectedDevice;
  160. //
  161. // Test get/set values
  162. //
  163. if (g_fTestSetGetValue) {
  164. TestGetSetValue(pszDeviceName);
  165. }
  166. //
  167. // If needed test notifications
  168. //
  169. if (g_fTestEDNotifications) {
  170. TestEnableDisableNotifications(pszDeviceName);
  171. }
  172. if (g_fTestLaunchAPI) {
  173. TestLaunchAPI(pszDeviceName);
  174. }
  175. if (g_fTestRefreshAPI) {
  176. TestRefreshAPI(pszDeviceName);
  177. }
  178. //
  179. // Create object for first device
  180. //
  181. if (g_fTestSCL) {
  182. dwMode |= STI_DEVICE_CREATE_DATA;
  183. }
  184. hres = g_pSti->CreateDevice(pszDeviceName,
  185. dwMode, // Mode
  186. &g_pStiDevice, // Result
  187. NULL ); // Controlling unk
  188. printf("CSTI: Creating device %s returned result=%x\n",pszDeviceName,hres);
  189. if (!SUCCEEDED(hres)) {
  190. printf("CSTI: Call failed - abort \n",hres);
  191. goto Cleanup;
  192. }
  193. //
  194. // Test second open on the same thread
  195. //
  196. hres = g_pSti->CreateDevice(pszDeviceName,
  197. dwMode, // Mode
  198. &g_pStiDevice1, // Result
  199. NULL ); // Controlling unk
  200. printf("CSTI: Creating device %s second time returned result=%x\n",pszDeviceName,hres);
  201. g_pStiDevice1->Release();
  202. g_pStiDevice1 = NULL;
  203. //
  204. // Test getting custom interface
  205. //
  206. TestQueryCustomInterface(pszDeviceName);
  207. //
  208. // Test online status
  209. //
  210. STI_DEVICE_STATUS DevStatus;
  211. ZeroMemory(&DevStatus,sizeof(DevStatus));
  212. printf("Getting online status.... :");
  213. DevStatus.StatusMask = STI_DEVSTATUS_ONLINE_STATE;
  214. hres = g_pStiDevice -> LockDevice(2000);
  215. printf("(Locking, ...hres=%X) ..",hres);
  216. hres = g_pStiDevice->GetStatus(&DevStatus);
  217. if (SUCCEEDED(hres) ) {
  218. if (DevStatus.dwEventHandlingState & STI_ONLINESTATE_OPERATIONAL ) {
  219. printf("Online\n");
  220. }
  221. else {
  222. printf("Offline\n");
  223. }
  224. }
  225. else {
  226. printf("Failed, panic...hres=%X\n",hres);
  227. }
  228. hres = g_pStiDevice -> UnLockDevice();
  229. if (g_fWait) {
  230. TestWaitForNotifications();
  231. }
  232. if (g_fTestSCL) {
  233. TestSCL();
  234. }
  235. //
  236. // Clean up and exit
  237. //
  238. Cleanup:
  239. if ( g_pStiDevice) {
  240. g_pStiDevice->UnLockDevice();
  241. g_pStiDevice->Release();
  242. }
  243. //
  244. // Delay exiting to test unload
  245. //
  246. printf("\nTo exit hit any key ...");
  247. _getch();
  248. if ( g_pSti) {
  249. g_pSti->Release();
  250. }
  251. return(0);
  252. }
  253. //
  254. //TestStiLaunch
  255. //
  256. BOOL
  257. TestStiLaunch(
  258. BOOL fRegister
  259. )
  260. {
  261. HRESULT hres;
  262. TCHAR szEventName[65] = {L'\0'};
  263. DWORD dwEventCode;
  264. DWORD cbData = sizeof(szEventName);
  265. BOOL fRet = FALSE;
  266. hres = g_pSti->GetSTILaunchInformation(szSelectedDevice,&dwEventCode,szEventName);
  267. if (SUCCEEDED(hres)) {
  268. CHAR szMessage[255];
  269. wsprintf(szMessage,"CSti: Launched through autopush. DeviceName:%s EventName:%s \n",szSelectedDevice,szEventName);
  270. g_pSti->WriteToErrorLog(STI_TRACE_INFORMATION,szMessage);
  271. printf(szMessage);
  272. fRet = TRUE;
  273. }
  274. //
  275. // Register us with STI as launch app
  276. //
  277. if (fRegister) {
  278. CHAR szModulePath[MAX_PATH+1+32];
  279. TCHAR szModulePathW[MAX_PATH+1];
  280. DWORD cch;
  281. cch = GetModuleFileName(NULL,szModulePath,sizeof(szModulePath));
  282. if (cch) {
  283. strcat(szModulePath," /Wait");
  284. #if 0
  285. cch = MultiByteToWideChar(CP_ACP, 0,
  286. szModulePath, -1,
  287. szModulePathW, sizeof(szModulePathW)
  288. );
  289. #endif
  290. hres = g_pSti->RegisterLaunchApplication(TEXT("Console STI Test"),szModulePath) ;
  291. }
  292. }
  293. return fRet;
  294. }
  295. //
  296. // TestEnumeration
  297. //
  298. VOID
  299. TestEnumerationAndSelect(
  300. BOOL fMakeSelection
  301. )
  302. {
  303. HRESULT hres;
  304. PVOID pBuffer;
  305. DWORD dwItemsReturned;
  306. UINT iCurrentSelection;
  307. UINT iDev;
  308. PSTI_DEVICE_INFORMATIONA pDevInfo;
  309. printf("CSTI: Running device enumeration\n");
  310. //
  311. // Enumerate devices
  312. //
  313. hres = g_pSti->GetDeviceList( 0, // Type
  314. 0, // Flags
  315. &dwItemsReturned,
  316. &pBuffer
  317. );
  318. printf("CSTI: Enumerating devices returned result=%x dwItemsReturned=%d\n",hres,dwItemsReturned);
  319. if (!SUCCEEDED(hres) || !pBuffer) {
  320. Beep(0,0);
  321. printf("CSTI Error : Call failed - abort \n",hres);
  322. return;
  323. }
  324. //
  325. // Print basic device information
  326. //
  327. pDevInfo = (PSTI_DEVICE_INFORMATIONA) pBuffer;
  328. for (iDev=0;
  329. iDev<dwItemsReturned ;
  330. iDev++,
  331. pDevInfo=(PSTI_DEVICE_INFORMATIONA)((LPBYTE)pDevInfo+pDevInfo->dwSize)
  332. ) {
  333. printf("\nImage device #%2d :\n",iDev+1);
  334. printf(" Type\t\t:%2d\n Internal name: %s\n",
  335. pDevInfo->DeviceType,
  336. pDevInfo->szDeviceInternalName
  337. );
  338. }
  339. printf("\n");
  340. if (*szSelectedDevice == L'\0') {
  341. printf("No currently selected device\n");
  342. }
  343. else {
  344. printf("Currently selected device:%s\n",szSelectedDevice);
  345. }
  346. pDevInfo = (PSTI_DEVICE_INFORMATIONA) pBuffer;
  347. if (fMakeSelection && dwItemsReturned) {
  348. *szSelectedDevice = L'\0';
  349. iCurrentSelection = 0;
  350. if ( dwItemsReturned == 1) {
  351. lstrcpy((LPSTR)szSelectedDevice,pDevInfo->szDeviceInternalName);
  352. printf("Only one device known, automatically selected device:%s\n",szSelectedDevice);
  353. }
  354. else {
  355. printf("Make a selection for currently active device:(1-%d)\n",dwItemsReturned);
  356. scanf("%2d",&iCurrentSelection);
  357. if (iCurrentSelection ==0 || iCurrentSelection > dwItemsReturned) {
  358. printf("CSTI Error: Invalid selection");
  359. }
  360. else {
  361. lstrcpy((LPSTR)szSelectedDevice,(pDevInfo+iCurrentSelection-1)->szDeviceInternalName);
  362. printf("Newly selected device:%s\n",szSelectedDevice);
  363. }
  364. }
  365. }
  366. if (pBuffer) {
  367. LocalFree(pBuffer);
  368. pBuffer = NULL;
  369. }
  370. }
  371. //
  372. // TestGetSetValue
  373. //
  374. TCHAR szTestValue[] = TEXT("TestValue");
  375. VOID
  376. TestGetSetValue(
  377. LPTSTR pszDeviceName
  378. )
  379. {
  380. HRESULT hRes;
  381. DWORD dwType;
  382. DWORD cbData;
  383. BYTE aData[255];
  384. printf("\nCSTI Testing get/set device value for device: %s\n\n",pszDeviceName);
  385. ::lstrcpy((LPSTR)aData,"TestValueMeaning");
  386. cbData = ::lstrlen((LPCSTR)aData) + sizeof(TCHAR);
  387. hRes = g_pSti->SetDeviceValue(pszDeviceName,szTestValue,REG_SZ,aData,cbData);
  388. printf("Wrote value :%s containing :%s Result=%x\n",
  389. szTestValue, (LPCSTR)aData, hRes);
  390. cbData = sizeof(aData);
  391. hRes = g_pSti->GetDeviceValue(pszDeviceName,szTestValue,&dwType,aData,&cbData);
  392. printf("Got back value :%s containing :%s dwType:%2d cbData:%4d Result=%x\n",
  393. szTestValue, (LPCSTR)aData, dwType, cbData,hRes);
  394. cbData = sizeof(aData);
  395. hRes = g_pSti->GetDeviceValue(pszDeviceName,STI_DEVICE_VALUE_TWAIN_NAME_A,&dwType,aData,&cbData);
  396. printf("Got back value :%s containing :%s dwType:%2d cbData:%4d Result=%x\n",
  397. STI_DEVICE_VALUE_TWAIN_NAME, (LPCSTR)aData, dwType, cbData,hRes);
  398. printf("\n\n");
  399. }
  400. VOID
  401. TestQueryCustomInterface(
  402. LPTSTR pszDeviceName
  403. )
  404. {
  405. }
  406. //
  407. //
  408. //
  409. VOID
  410. TestSCL(
  411. VOID
  412. )
  413. {
  414. HRESULT hres;
  415. STI_DEVICE_STATUS DevStatus;
  416. CHAR ScanData[1024*16];
  417. ULONG cbDataSize;
  418. UINT xRes = 0;
  419. BOOL fLocked = FALSE;
  420. //
  421. // Try to communicate to device in raw mode
  422. //
  423. g_pStiDevice->LockDevice(2000);
  424. // Resetting device
  425. g_pStiDevice->DeviceReset();
  426. //
  427. // Get and display status
  428. //
  429. ZeroMemory(&DevStatus,sizeof(DevStatus));
  430. hres = g_pStiDevice->GetStatus(&DevStatus);
  431. if (!SUCCEEDED(hres) ) {
  432. printf("CSTI: Get status call failed - abort \n",hres);
  433. }
  434. else {
  435. }
  436. //
  437. // Test lamp on/of capability
  438. //
  439. hres = SendDeviceCommandString(g_pStiDevice,LampOn);
  440. printf("\nHit any key...");
  441. _getch();
  442. hres = SendDeviceCommandString(g_pStiDevice,LampOff);
  443. printf("\n");
  444. //
  445. // Inquire commands ( X and Y resolution)
  446. //
  447. cbDataSize = sizeof(ScanData);
  448. ZeroMemory(ScanData,sizeof(ScanData));
  449. hres = TransactDevice(g_pStiDevice,ScanData,cbDataSize,InqXRes);
  450. if (SUCCEEDED(hres) ) {
  451. sscanf(ScanData,"%d",&xRes);
  452. printf("CSTI: XRes = %d\n",xRes);
  453. }
  454. //
  455. // Get status
  456. //
  457. printf(" Start polling for button.......");
  458. #ifndef USE_GETSTATUS
  459. while (TRUE) {
  460. ZeroMemory(ScanData,sizeof(ScanData));
  461. hres = SendDeviceCommandString(g_pStiDevice,PollButton);
  462. if (SUCCEEDED(hres) ) {
  463. cbDataSize = sizeof(ScanData);
  464. hres = g_pStiDevice->RawReadData(ScanData,&cbDataSize,NULL);
  465. if (SUCCEEDED(hres) ) {
  466. printf("CSTI: Got data from polling Size=(%d) Data=(%s)\n",cbDataSize,ScanData);
  467. }
  468. }
  469. Sleep(2000);
  470. }
  471. #else
  472. while (TRUE) {
  473. printf("\nLocking device");
  474. if (SUCCEEDED(hres) ) {
  475. ZeroMemory(&DevStatus,sizeof(DevStatus));
  476. DevStatus.StatusMask = STI_DEVSTATUS_EVENTS_STATE;
  477. hres = g_pStiDevice->GetStatus(&DevStatus);
  478. printf("\nGot status");
  479. if (SUCCEEDED(hres) ) {
  480. if (DevStatus.dwEventHandlingState & STI_EVENTHANDLING_PENDING ) {
  481. printf("\nEvent detected");
  482. g_pStiDevice->DeviceReset();
  483. }
  484. }
  485. }
  486. Sleep(2000);
  487. }
  488. #endif
  489. printf("\nTo start scanning , hit any key...");
  490. _getch();
  491. //
  492. // Perform scan
  493. //
  494. hres = SendDeviceCommandString(g_pStiDevice,ScanCmd);
  495. UINT i=0;
  496. do {
  497. cbDataSize = sizeof(ScanData);
  498. hres = g_pStiDevice->RawReadData(ScanData,&cbDataSize,NULL);
  499. if (cbDataSize == sizeof (ScanData)) {
  500. i++;
  501. printf (".");
  502. }
  503. } while ( cbDataSize == sizeof (ScanData));
  504. printf ("\n CSTI: Scan done total Bytes = %ld.\n",(sizeof(ScanData))*i+cbDataSize);
  505. }
  506. //
  507. //
  508. //
  509. VOID
  510. TestWaitForNotifications(
  511. VOID
  512. )
  513. {
  514. HANDLE hWaitEvent;
  515. HRESULT hres;
  516. BOOL fWaiting = TRUE;
  517. DWORD dwErr = 0x56565656;
  518. hWaitEvent = CreateEvent( NULL, // Attributes
  519. FALSE, // Manual reset
  520. FALSE, // Initial state
  521. NULL ); // Name
  522. if ( !hWaitEvent ) {
  523. return;
  524. }
  525. STISUBSCRIBE sSubscribe;
  526. ZeroMemory(&sSubscribe,sizeof(sSubscribe));
  527. sSubscribe.dwSize = sizeof(STISUBSCRIBE);
  528. sSubscribe.dwFlags = STI_SUBSCRIBE_FLAG_EVENT ;
  529. sSubscribe.hWndNotify = NULL;
  530. sSubscribe.hEvent = hWaitEvent;
  531. sSubscribe.uiNotificationMessage = 0;
  532. hres = g_pStiDevice->Subscribe(&sSubscribe);
  533. printf("CSTI::Device::Attempted to subscribe . Returned %xh %u\n",hres,hres);
  534. printf("CSTI Waiing for notifications on device ( to stop press Q)..........\n");
  535. while (fWaiting) {
  536. dwErr = WaitForSingleObject(hWaitEvent,1000);
  537. switch (dwErr) {
  538. case WAIT_OBJECT_0:
  539. {
  540. //
  541. // Something came
  542. //
  543. STINOTIFY sNotify;
  544. ZeroMemory(&sNotify,sizeof(sNotify));
  545. sNotify.dwSize = sizeof(sNotify);
  546. printf("Received notification from opened device :");
  547. hres = g_pStiDevice->GetLastNotificationData(&sNotify);
  548. if (SUCCEEDED(hres)) {
  549. printf("GUID={%8x-%4x-%4x-%lx}\n",
  550. sNotify.guidNotificationCode.Data1,
  551. sNotify.guidNotificationCode.Data2,
  552. sNotify.guidNotificationCode.Data3,
  553. (ULONG_PTR)sNotify.guidNotificationCode.Data4
  554. );
  555. }
  556. else {
  557. printf("Failed get data hres=%X\n",hres);
  558. }
  559. }
  560. break;
  561. case WAIT_TIMEOUT:
  562. // Fall through
  563. default:
  564. //
  565. // Check for keyboard input
  566. //
  567. if (_kbhit()) {
  568. int ch;
  569. ch = _getch();
  570. if (toupper(ch) == 'Q') {
  571. fWaiting = FALSE;
  572. }
  573. }
  574. break;
  575. }
  576. }
  577. hres = g_pStiDevice->UnSubscribe();
  578. printf("CSTI::Device::UnSubscribing Returned %xh %u\n",hres,hres);
  579. }
  580. //
  581. // Test Enable/Disable notfications on a device
  582. //
  583. VOID
  584. TestEnableDisableNotifications(
  585. LPTSTR pszDeviceName
  586. )
  587. {
  588. int ch = '\0';
  589. BOOL fLooping = TRUE;
  590. BOOL fState = FALSE;
  591. HRESULT hRes;
  592. printf("\nCSTI: Testing enable/disable notfications functionality for device: %s\n\n",pszDeviceName);
  593. while (fLooping) {
  594. hRes = g_pSti->GetHwNotificationState(pszDeviceName,&fState);
  595. if (SUCCEEDED(hRes)) {
  596. printf("Current notifcation state is: %s. (E,D,Q) >",
  597. fState ? "Enabled" : "Disabled");
  598. }
  599. else {
  600. printf("Failed to get notification state, exiting ");
  601. exit(0);
  602. }
  603. ch = _getch();
  604. if (toupper(ch) == 'Q') {
  605. fLooping = FALSE;
  606. }
  607. else if (toupper(ch) == 'E') {
  608. g_pSti->EnableHwNotifications(pszDeviceName,TRUE);
  609. }
  610. else if (toupper(ch) == 'D') {
  611. g_pSti->EnableHwNotifications(pszDeviceName,FALSE);
  612. }
  613. printf("\n");
  614. }
  615. }
  616. //
  617. // Test external launch API
  618. //
  619. VOID
  620. TestLaunchAPI(
  621. LPTSTR pszDeviceName
  622. )
  623. {
  624. BOOL fLooping = TRUE;
  625. HRESULT hRes;
  626. TCHAR wszAppName[] = TEXT("HP PictureScan 3.0");
  627. GUID guidLaunchEvent = guidGreenButton;
  628. STINOTIFY sStiNotify;
  629. printf("\nCSTI: Testing external launching for device: %s\n\n",pszDeviceName);
  630. //printf("Enter name of the registered application to launch on a device:");
  631. ::ZeroMemory(&sStiNotify,sizeof(sStiNotify));
  632. sStiNotify.dwSize = sizeof(sStiNotify);
  633. sStiNotify.guidNotificationCode = guidLaunchEvent;
  634. hRes = g_pSti->LaunchApplicationForDevice(pszDeviceName,wszAppName,&sStiNotify);
  635. printf("CSTI: Launching application (%s) hResult=%x \n",wszAppName,hRes);
  636. }
  637. //
  638. // Bus refresh
  639. //
  640. VOID
  641. TestRefreshAPI(
  642. LPTSTR pszDeviceName
  643. )
  644. {
  645. HRESULT hRes;
  646. printf("\nCSTI: Testing bus refresh for device: %s\n\n",pszDeviceName);
  647. hRes = g_pSti->RefreshDeviceBus(pszDeviceName);
  648. printf("CSTI: After bus refresh hResult=%x \n",hRes);
  649. }
  650. /*
  651. * Send formatted SCL string to the device
  652. *
  653. */
  654. HRESULT
  655. WINAPI
  656. SendDeviceCommandString(
  657. PSTIDEVICE pStiDevice,
  658. LPSTR pszFormat,
  659. ...
  660. )
  661. {
  662. CHAR ScanCommand[255];
  663. UINT cbChar;
  664. HRESULT hres;
  665. // Format command string
  666. ZeroMemory(ScanCommand,sizeof(ScanCommand)); // blank command
  667. ScanCommand[0]='\033'; // stuff with Reset()
  668. cbChar = 1;
  669. va_list ap;
  670. va_start(ap, pszFormat);
  671. cbChar += vsprintf(ScanCommand+1, pszFormat, ap);
  672. va_end(ap);
  673. // Send it to the device
  674. hres = pStiDevice->RawWriteData(ScanCommand,cbChar,NULL);
  675. printf("CSTISendFormattoDevice: First byte : %2x Rest of string: %s returned result=%x\n",
  676. ScanCommand[0],ScanCommand+1,hres);
  677. return hres;
  678. }
  679. HRESULT
  680. WINAPI
  681. TransactDevice(
  682. PSTIDEVICE pStiDevice,
  683. LPSTR lpResultBuffer,
  684. UINT cbResultBufferSize,
  685. LPSTR pszFormat,
  686. ...
  687. )
  688. {
  689. CHAR ScanCommand[255];
  690. UINT cbChar;
  691. ULONG cbActual;
  692. HRESULT hres;
  693. // Format command string
  694. ZeroMemory(ScanCommand,sizeof(ScanCommand));
  695. ScanCommand[0]='\033';
  696. cbChar = 1;
  697. va_list ap;
  698. va_start(ap, pszFormat);
  699. cbChar += vsprintf(ScanCommand+1, pszFormat, ap);
  700. va_end(ap);
  701. // Send it to the device
  702. cbActual = 0;
  703. hres = S_OK;
  704. // hres = pStiDevice->Escape(StiTransact,ScanCommand,cbChar,lpResultBuffer,cbResultBufferSize,&cbActual);
  705. printf("CSTITransact : First byte : %2x Rest of string: %s returned result=%x\n",
  706. ScanCommand[0],ScanCommand+1,hres);
  707. return hres;
  708. }
  709. BOOL WINAPI
  710. FormatStringV(
  711. IN LPTSTR lpszStr,
  712. //LPSTR lpszFirst,
  713. ...
  714. )
  715. {
  716. DWORD cch;
  717. LPSTR pchBuff;
  718. BOOL fRet = FALSE;
  719. DWORD dwErr;
  720. va_list va;
  721. va_start(va,lpszStr);
  722. //va_arg(va,LPSTR);
  723. cch = ::FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  724. FORMAT_MESSAGE_FROM_STRING,
  725. lpszStr,
  726. 0L,
  727. 0,
  728. (LPSTR) &pchBuff,
  729. 1024,
  730. &va);
  731. dwErr = ::GetLastError();
  732. if ( cch ) {
  733. ::lstrcpy(lpszStr,(LPCSTR) pchBuff );
  734. ::LocalFree( (VOID*) pchBuff );
  735. }
  736. return fRet;
  737. }
  738. //
  739. // Parse command line
  740. //
  741. VOID
  742. ProcessCommandLine(
  743. INT cArgs,
  744. char * pArgs[]
  745. )
  746. {
  747. if (cArgs < 2) {
  748. return;
  749. }
  750. LPSTR pOption;
  751. for (INT i=1;i<cArgs;i++) {
  752. pOption = pArgs[i];
  753. // Skip delimiter
  754. if (*pOption == '/' || *pOption == '-') {
  755. pOption++;
  756. }
  757. if (!*pOption) {
  758. continue;
  759. }
  760. // Set globals
  761. if (!_stricmp(pOption,"Wait")) {
  762. g_fWait = TRUE;
  763. }
  764. else if (!_stricmp(pOption,"SCL")) {
  765. g_fTestSCL = TRUE;
  766. }
  767. else if (!_stricmp(pOption,"EDN")) {
  768. g_fTestEDNotifications = TRUE;
  769. }
  770. else if (!_stricmp(pOption,"LAUNCH")) {
  771. g_fTestLaunchAPI = TRUE;
  772. }
  773. else if (!_stricmp(pOption,"REFRESH")) {
  774. g_fTestRefreshAPI = TRUE;
  775. }
  776. }
  777. }