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.

811 lines
21 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. tracedp.c
  5. Abstract:
  6. Sample trace provider program.
  7. // end_sdk
  8. Author:
  9. Jee Fung Pang (jeepang) 03-Dec-1997
  10. Revision History:
  11. Insung Park (insungp) 18-Jan-2001
  12. Modified tracedp so that when tracedp generates User Mof Events
  13. with some sample strings, integers, floats, and arrays.
  14. // begin_sdk
  15. --*/
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <windows.h>
  19. #include <shellapi.h>
  20. #include <tchar.h>
  21. #include <ntverp.h>
  22. #include <fcntl.h>
  23. #include <wmistr.h>
  24. #include <guiddef.h>
  25. #include <evntrace.h>
  26. #define MAXEVENTS 5000
  27. #define MAXSTR 1024
  28. #define MAXTHREADS 128
  29. // sample string data
  30. #define WIDE_DATA_STRING L"Sample Wide String"
  31. #define COUNTED_DATA_STRING L"Sample Counted String"
  32. TRACEHANDLE LoggerHandle;
  33. #define ResourceName _T("MofResource")
  34. TCHAR ImagePath[MAXSTR];
  35. GUID TransactionGuid =
  36. {0xce5b1020, 0x8ea9, 0x11d0, 0xa4, 0xec, 0x00, 0xa0, 0xc9, 0x06, 0x29, 0x10};
  37. GUID ControlGuid[2] =
  38. {
  39. {0xd58c126f, 0xb309, 0x11d1, 0x96, 0x9e, 0x00, 0x00, 0xf8, 0x75, 0xa5, 0xbc},
  40. {0x7c6a708a, 0xba1e, 0x11d2, 0x8b, 0xbf, 0x00, 0x00, 0xf8, 0x06, 0xef, 0xe0}
  41. };
  42. TRACE_GUID_REGISTRATION TraceGuidReg[] =
  43. {
  44. { (LPGUID)&TransactionGuid,
  45. NULL
  46. }
  47. };
  48. typedef enum {
  49. TYPE_USER_EVENT,
  50. TYPE_INSTANCE_EVENT,
  51. TYPE_MOF_EVENT,
  52. TYPEPTR_GUID
  53. } TypeEventType;
  54. typedef struct _USER_EVENT {
  55. EVENT_TRACE_HEADER Header;
  56. ULONG EventInfo;
  57. } USER_EVENT, *PUSER_EVENT;
  58. typedef struct _USER_INSTANCE_EVENT {
  59. EVENT_INSTANCE_HEADER Header;
  60. ULONG mofData;
  61. } USER_INSTANCE_EVENT, *PUSER_INSTANCE_EVENT;
  62. // customized event to use sample data that follow
  63. typedef struct _USER_MOF_EVENT {
  64. EVENT_TRACE_HEADER Header;
  65. MOF_FIELD mofData;
  66. } USER_MOF_EVENT, *PUSER_MOF_EVENT;
  67. // sample data structure
  68. typedef struct _INTEGER_SAMPLE_EVENT {
  69. CHAR sc;
  70. UCHAR uc;
  71. SHORT sh;
  72. ULONG ul;
  73. } INTEGER_SAMPLE_EVENT, *PINTEGER_SAMPLE_EVENT;
  74. typedef struct _FLOAT_SAMPLE_EVENT {
  75. float fl;
  76. double db;
  77. } FLOAT_SAMPLE_EVENT, *PFLOAT_SAMPLE_EVENT;
  78. typedef struct _ARRAY_SAMPLE_EVENT {
  79. CHAR ca[9];
  80. } ARRAY_SAMPLE_EVENT, *PARRAY_SAMPLE_EVENT;
  81. TypeEventType EventType = TYPE_USER_EVENT;
  82. TRACEHANDLE RegistrationHandle[2];
  83. BOOLEAN TraceOnFlag;
  84. ULONG EnableLevel = 0;
  85. ULONG EnableFlags = 0;
  86. BOOLEAN bPersistData = FALSE;
  87. ULONG nSleepTime = 0;
  88. ULONG EventCount = 0;
  89. BOOLEAN bInstanceTrace=0, bUseGuidPtr=0, bUseMofPtr=0;
  90. BOOLEAN bIncorrect = FALSE;
  91. BOOLEAN bUseNullPtr = FALSE;
  92. BOOLEAN bFirstTime = TRUE;
  93. ULONG InitializeTrace(
  94. void
  95. );
  96. ULONG
  97. ControlCallback(
  98. IN WMIDPREQUESTCODE RequestCode,
  99. IN PVOID Context,
  100. IN OUT ULONG *InOutBufferSize,
  101. IN OUT PVOID Buffer
  102. );
  103. LPTSTR
  104. DecodeStatus(
  105. IN ULONG Status
  106. );
  107. void
  108. LogProc();
  109. LPTSTR
  110. GuidToString(
  111. LPTSTR s,
  112. LPGUID piid
  113. );
  114. TCHAR ErrorMsg[MAXSTR];
  115. ULONG MaxEvents = MAXEVENTS;
  116. ULONG gnMultiReg=1;
  117. BOOLEAN RegistrationSuccess;
  118. void StringToGuid(
  119. TCHAR *str,
  120. LPGUID guid
  121. )
  122. /*++
  123. Routine Description:
  124. Converts a String into a GUID.
  125. Arguments:
  126. str - String representing a GUID.
  127. guid - Pointer to a GUID for ourput
  128. Return Value:
  129. None.
  130. --*/
  131. {
  132. TCHAR temp[10];
  133. int i, n;
  134. temp[8]=_T('\0');
  135. _tcsncpy(temp, str, 8);
  136. _stscanf(temp, _T("%x"), &(guid->Data1));
  137. temp[4]=_T('\0');
  138. _tcsncpy(temp, &str[9], 4);
  139. _stscanf(temp, _T("%x"), &(guid->Data2));
  140. _tcsncpy(temp, &str[14], 4);
  141. _stscanf(temp, _T("%x"), &(guid->Data3));
  142. temp[2]='\0';
  143. for(i=0;i<8;i++)
  144. {
  145. temp[0]=str[19+((i<2)?2*i:2*i+1)]; // to accomodate the minus sign after
  146. temp[1]=str[20+((i<2)?2*i:2*i+1)]; // the first two chars
  147. _stscanf(temp, _T("%x"), &n); // if used more than byte alloc
  148. guid->Data4[i]=(unsigned char)n; // causes overrun of memory
  149. }
  150. }
  151. __cdecl main(argc, argv)
  152. int argc;
  153. char **argv;
  154. /*++
  155. Routine Description:
  156. main() routine.
  157. Arguments:
  158. Usage: TraceDp [options] [number of events]
  159. -UseEventTraceHeader this is default.
  160. -UseEventInstanceHeader
  161. -UseMofPtrFlag
  162. -Thread [n] Sets the number of event-generating threads.
  163. -GuidPtr Use GUID pointer instead of GUID itself.
  164. -MofPtr Use MOF pointer for additional data.
  165. -GuidPtrMofPtr User GUID pointer and MOF pointer.
  166. -InCorrectMofPtr Use incorrect MOF pointer (Creates an error case).
  167. -NullMofPtr Use NULL MOF pointer (Creates an error case).
  168. -MultiReg Register multiple event GUIDS.
  169. -Sleep [n] Sets the sleep time before unregistering.
  170. [number of events] default is 5000
  171. Return Value:
  172. Error Code defined in winerror.h : If the function succeeds,
  173. it returns ERROR_SUCCESS (== 0).
  174. --*/
  175. {
  176. ULONG status;
  177. ULONG InstanceId;
  178. LPGUID Guid = NULL;
  179. PWNODE_HEADER Wnode;
  180. TCHAR strMofData[MAXSTR];
  181. DWORD ThreadId;
  182. HANDLE hThreadVector[MAXTHREADS];
  183. ULONG i;
  184. ULONG nThreads = 1;
  185. char s[MAXSTR];
  186. LPTSTR *targv;
  187. MaxEvents = MAXEVENTS;
  188. TraceOnFlag = FALSE;
  189. #ifdef UNICODE
  190. if ((targv = CommandLineToArgvW(
  191. GetCommandLineW(), // pointer to a command-line string
  192. &argc // receives the argument count
  193. )) == NULL)
  194. {
  195. return(GetLastError());
  196. };
  197. #else
  198. targv = argv;
  199. #endif
  200. // process command line arguments to override defaults
  201. //
  202. while (--argc > 0)
  203. {
  204. targv ++;
  205. if (**targv == '-' || **targv == '/')
  206. {
  207. if(targv[0][0] == '/' ) targv[0][0] = '-';
  208. if (!_tcsicmp(targv[0],_T("-UseEventTraceHeader")))
  209. {
  210. EventType = TYPE_USER_EVENT;
  211. }
  212. else if (!_tcsicmp(targv[0],_T("-UseEventInstanceHeader")))
  213. {
  214. EventType = TYPE_INSTANCE_EVENT;
  215. }
  216. else if (!_tcsicmp(targv[0],_T("-UseMofPtrFlag")))
  217. {
  218. EventType = TYPE_MOF_EVENT;
  219. }
  220. // end_sdk
  221. else if (!_tcsicmp(targv[0],_T("-Persist")))
  222. {
  223. bPersistData = TRUE;
  224. }
  225. // begin_sdk
  226. else if (!_tcsicmp(targv[0],_T("-Thread")))
  227. {
  228. if (argc > 1) {
  229. targv++; --argc;
  230. nThreads = _ttoi(targv[0]);
  231. if (nThreads > MAXTHREADS)
  232. nThreads = MAXTHREADS;
  233. }
  234. }
  235. else if (!_tcsicmp(targv[0],_T("-GuidPtr")))
  236. {
  237. bUseGuidPtr = TRUE;
  238. }
  239. else if (!_tcsicmp(targv[0],_T("-MofPtr")))
  240. {
  241. bUseMofPtr = TRUE;
  242. }
  243. else if (!_tcsicmp(targv[0],_T("-GuidPtrMofPtr")))
  244. {
  245. bUseGuidPtr = TRUE;
  246. bUseMofPtr = TRUE;
  247. }
  248. else if (!_tcsicmp(targv[0],_T("-InCorrectMofPtr")))
  249. {
  250. bUseMofPtr = TRUE;
  251. bIncorrect = TRUE;
  252. }
  253. else if (!_tcsicmp(targv[0],_T("-NullMofPtr")))
  254. {
  255. bUseMofPtr = TRUE;
  256. bUseNullPtr = TRUE;
  257. bIncorrect = TRUE;;
  258. }
  259. else if (!_tcsicmp(targv[0],_T("-MultiReg")))
  260. {
  261. gnMultiReg = 2;
  262. }
  263. else if (!_tcsicmp(targv[0], _T("-guid"))) {
  264. if (argc > 1) {
  265. if (targv[1][0] == _T('#')) {
  266. StringToGuid(&targv[1][1], &ControlGuid[0]);
  267. ++targv; --argc;
  268. }
  269. }
  270. }
  271. else if (!_tcsicmp(targv[0],_T("-Sleep")))
  272. {
  273. if (argc > 1) {
  274. targv++; --argc;
  275. nSleepTime = _ttoi(targv[0]);
  276. }
  277. }
  278. else
  279. {
  280. printf("Usage: TraceDp [options] [number of events]\n");
  281. printf("\t-UseEventTraceHeader this is default.\n");
  282. printf("\t-UseEventInstanceHeader\n");
  283. printf("\t-UseMofPtrFlag\n");
  284. printf("\t-Thread [n]\n");
  285. printf("\t-GuidPtr\n");
  286. printf("\t-MofPtr\n");
  287. printf("\t-GuidPtrMofPtr\n");
  288. printf("\t-InCorrectMofPtr\n");
  289. printf("\t-NullMofPtr\n");
  290. printf("\t-MultiReg\n");
  291. printf("\t-Sleep [n]\n");
  292. printf("\t[number of events] default is 5000\n");
  293. return 0;
  294. }
  295. }
  296. else if (** targv >= '0' && ** targv <= '9')
  297. {
  298. MaxEvents = _ttoi(targv[0]);
  299. }
  300. }
  301. status = InitializeTrace();
  302. if (status != ERROR_SUCCESS) {
  303. return 0;
  304. }
  305. _tprintf(_T("Testing Logger with %d events (%d,%d)\n"),
  306. MaxEvents, EventType, bPersistData);
  307. while (! TraceOnFlag)
  308. _sleep(1000);
  309. for (i=0; i < nThreads; i++) {
  310. hThreadVector[i] = CreateThread(NULL,
  311. 0,
  312. (LPTHREAD_START_ROUTINE) LogProc,
  313. NULL,
  314. 0,
  315. (LPDWORD)&ThreadId);
  316. }
  317. WaitForMultipleObjects(nThreads, hThreadVector, TRUE, INFINITE);
  318. if (nSleepTime > 0) {
  319. _sleep(nSleepTime * 1000);
  320. }
  321. for (i=0; i<gnMultiReg; i++) {
  322. UnregisterTraceGuids(RegistrationHandle[i]);
  323. }
  324. return status;
  325. }
  326. LPTSTR
  327. DecodeStatus(
  328. IN ULONG Status
  329. )
  330. /*++
  331. Routine Description:
  332. Decodes error status.
  333. Arguments:
  334. Status - Return status of function calls to be decoded.
  335. Return Value:
  336. Pointer to a decoded error message.
  337. --*/
  338. {
  339. memset( ErrorMsg, 0, MAXSTR );
  340. FormatMessage(
  341. FORMAT_MESSAGE_FROM_SYSTEM |
  342. FORMAT_MESSAGE_IGNORE_INSERTS,
  343. NULL,
  344. Status,
  345. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  346. (LPTSTR) ErrorMsg,
  347. MAXSTR,
  348. NULL );
  349. return ErrorMsg;
  350. }
  351. ULONG InitializeTrace(
  352. void
  353. )
  354. /*++
  355. Routine Description:
  356. Register traces.
  357. Arguments:
  358. Return Value:
  359. Error Status. ERROR_SUCCESS if successful.
  360. --*/
  361. {
  362. ULONG Status;
  363. ULONG i, j;
  364. Status = GetModuleFileName(NULL, &ImagePath[0], MAXSTR*sizeof(TCHAR));
  365. if (Status == 0) {
  366. return (ERROR_FILE_NOT_FOUND);
  367. }
  368. for (i=0; i<gnMultiReg; i++) {
  369. TCHAR str[MAXSTR];
  370. Status = RegisterTraceGuids(
  371. (WMIDPREQUEST)ControlCallback, //use same callback function
  372. (PVOID)(INT_PTR)(0x12345678+i), // RequestContext
  373. (LPCGUID)&ControlGuid[i],
  374. 1,
  375. &TraceGuidReg[i],
  376. (LPCTSTR)&ImagePath[0],
  377. (LPCTSTR)ResourceName,
  378. &RegistrationHandle[i]
  379. );
  380. if (Status != ERROR_SUCCESS) {
  381. _tprintf(_T("Trace registration failed\n"));
  382. RegistrationSuccess = FALSE;
  383. if( i > 0) {
  384. for (j=0; j<i; j++) {
  385. UnregisterTraceGuids(RegistrationHandle[i]);
  386. }
  387. }
  388. _tprintf(_T("InitializeTrace failed. i=%d, status=%d, %s\n"), i, Status, DecodeStatus(Status));
  389. return(Status);
  390. }
  391. else {
  392. _tprintf(_T("Trace registered successfully\n"));
  393. RegistrationSuccess = TRUE;
  394. }
  395. }
  396. return(Status);
  397. }
  398. ULONG
  399. ControlCallback(
  400. IN WMIDPREQUESTCODE RequestCode,
  401. IN PVOID Context,
  402. IN OUT ULONG *InOutBufferSize,
  403. IN OUT PVOID Buffer
  404. )
  405. /*++
  406. Routine Description:
  407. Callback function when enabled.
  408. Arguments:
  409. RequestCode - Flag for either enable or disable.
  410. Context - User-defined context.
  411. InOutBufferSize - not used.
  412. Buffer - WNODE_HEADER for the logger session.
  413. Return Value:
  414. Error Status. ERROR_SUCCESS if successful.
  415. --*/
  416. {
  417. ULONG Status;
  418. ULONG RetSize;
  419. Status = ERROR_SUCCESS;
  420. switch (RequestCode)
  421. {
  422. case WMI_ENABLE_EVENTS:
  423. {
  424. RetSize = 0;
  425. LoggerHandle = GetTraceLoggerHandle( Buffer );
  426. EnableLevel = GetTraceEnableLevel(LoggerHandle);
  427. EnableFlags = GetTraceEnableFlags(LoggerHandle);
  428. _tprintf(_T("Logging enabled to 0x%016I64x(%d,%d,%d)\n"),
  429. LoggerHandle, RequestCode, EnableLevel, EnableFlags);
  430. TraceOnFlag = TRUE;
  431. break;
  432. }
  433. case WMI_DISABLE_EVENTS:
  434. {
  435. TraceOnFlag = FALSE;
  436. RetSize = 0;
  437. LoggerHandle = 0;
  438. _tprintf(_T("\nLogging Disabled\n"));
  439. break;
  440. }
  441. default:
  442. {
  443. RetSize = 0;
  444. Status = ERROR_INVALID_PARAMETER;
  445. break;
  446. }
  447. }
  448. *InOutBufferSize = RetSize;
  449. return(Status);
  450. }
  451. void
  452. LogProc()
  453. /*++
  454. Routine Description:
  455. Generates events. It is spawned as separate threads.
  456. Based on the options given by users, it generates different events.
  457. Arguments:
  458. Return Value:
  459. None.
  460. --*/
  461. {
  462. USER_EVENT UserEvent;
  463. USER_INSTANCE_EVENT UserInstanceEvent;
  464. USER_MOF_EVENT UserMofEvent;
  465. EVENT_INSTANCE_INFO InstInfo;
  466. PMOF_FIELD mofField;
  467. ULONG i;
  468. PWNODE_HEADER Wnode;
  469. ULONG status;
  470. ULONG InstanceId;
  471. LPGUID Guid = NULL;
  472. ULONG nTemp;
  473. USHORT nSize, nStrEventSize;
  474. WCHAR wstrTemp[MAXSTR];
  475. INTEGER_SAMPLE_EVENT ise;
  476. FLOAT_SAMPLE_EVENT fse;
  477. ARRAY_SAMPLE_EVENT ase;
  478. CHAR *sse, *ptr;
  479. // some arbitrary data for MOF structs
  480. ise.sc = 'x';
  481. ise.uc = 'y';
  482. ise.sh = (SHORT)rand();
  483. ise.ul = (ULONG)rand();
  484. nTemp = 0;
  485. while (nTemp == 0) {
  486. nTemp = rand();
  487. }
  488. fse.fl = ((float)rand() / (float)nTemp);
  489. fse.db = ((double)rand() / (double)nTemp);
  490. ase.ca[0] = 'M';
  491. ase.ca[1] = 'i';
  492. ase.ca[2] = 'c';
  493. ase.ca[3] = 'r';
  494. ase.ca[4] = 'o';
  495. ase.ca[5] = 's';
  496. ase.ca[6] = 'o';
  497. ase.ca[7] = 'f';
  498. ase.ca[8] = 't';
  499. nStrEventSize = ((wcslen(WIDE_DATA_STRING) + 1) * sizeof(WCHAR)) + sizeof(SHORT) + (wcslen(COUNTED_DATA_STRING) * sizeof(WCHAR));
  500. sse = (PCHAR) malloc(nStrEventSize);
  501. if (NULL != sse) {
  502. ptr = sse;
  503. wcscpy(wstrTemp, WIDE_DATA_STRING);
  504. wstrTemp[wcslen(WIDE_DATA_STRING)] = L'\0';
  505. memcpy(ptr, wstrTemp, (wcslen(WIDE_DATA_STRING) + 1) * sizeof(WCHAR));
  506. ptr += (wcslen(WIDE_DATA_STRING) + 1) * sizeof(WCHAR);
  507. nSize = (USHORT)(wcslen(COUNTED_DATA_STRING) * sizeof(WCHAR));
  508. memcpy(ptr, &nSize, sizeof(USHORT));
  509. ptr += sizeof(USHORT);
  510. wcscpy(wstrTemp, COUNTED_DATA_STRING);
  511. memcpy(ptr, wstrTemp, wcslen(COUNTED_DATA_STRING) * sizeof(WCHAR));
  512. }
  513. RtlZeroMemory(&UserEvent, sizeof(UserEvent));
  514. Wnode = (PWNODE_HEADER) &UserEvent;
  515. UserEvent.Header.Size = sizeof(USER_EVENT);
  516. UserEvent.Header.Flags = WNODE_FLAG_TRACED_GUID;
  517. UserEvent.Header.Guid = TransactionGuid;
  518. if (bPersistData)
  519. UserEvent.Header.Flags |= WNODE_FLAG_PERSIST_EVENT;
  520. RtlZeroMemory(&UserInstanceEvent, sizeof(UserInstanceEvent));
  521. UserInstanceEvent.Header.Size = sizeof(UserInstanceEvent);
  522. UserInstanceEvent.Header.Flags = WNODE_FLAG_TRACED_GUID;
  523. if (bPersistData)
  524. UserInstanceEvent.Header.Flags |= WNODE_FLAG_PERSIST_EVENT;
  525. RtlZeroMemory(&UserMofEvent, sizeof(UserMofEvent));
  526. Wnode = (PWNODE_HEADER) &UserMofEvent;
  527. UserMofEvent.Header.Size = sizeof(UserMofEvent);
  528. UserMofEvent.Header.Flags = WNODE_FLAG_TRACED_GUID;
  529. UserMofEvent.Header.Guid = TransactionGuid;
  530. // end_sdk
  531. if (bPersistData)
  532. UserMofEvent.Header.Flags |= WNODE_FLAG_PERSIST_EVENT;
  533. // begin_sdk
  534. if (bUseGuidPtr) {
  535. UserEvent.Header.Flags |= WNODE_FLAG_USE_GUID_PTR;
  536. UserEvent.Header.GuidPtr = (ULONGLONG)&TransactionGuid;
  537. UserMofEvent.Header.Flags |= WNODE_FLAG_USE_GUID_PTR;
  538. UserMofEvent.Header.GuidPtr = (ULONGLONG)&TransactionGuid;
  539. }
  540. i = 0;
  541. while (TraceOnFlag) {
  542. if ((i % 4) == 0) {
  543. UserEvent.Header.Class.Type = EVENT_TRACE_TYPE_START;
  544. UserInstanceEvent.Header.Class.Type = EVENT_TRACE_TYPE_START;
  545. UserMofEvent.Header.Class.Type = 1;
  546. }
  547. else if ((i % 4) == 1) {
  548. UserEvent.Header.Class.Type = EVENT_TRACE_TYPE_END;
  549. UserInstanceEvent.Header.Class.Type = EVENT_TRACE_TYPE_END;
  550. UserMofEvent.Header.Class.Type = 2;
  551. }
  552. else if ((i % 4) == 2) {
  553. UserEvent.Header.Class.Type = EVENT_TRACE_TYPE_START;
  554. UserInstanceEvent.Header.Class.Type = EVENT_TRACE_TYPE_START;
  555. UserMofEvent.Header.Class.Type = 3;
  556. }
  557. else {
  558. UserEvent.Header.Class.Type = EVENT_TRACE_TYPE_END;
  559. UserInstanceEvent.Header.Class.Type = EVENT_TRACE_TYPE_END;
  560. UserMofEvent.Header.Class.Type = 4;
  561. }
  562. switch (EventType)
  563. {
  564. case TYPE_INSTANCE_EVENT:
  565. if (UserInstanceEvent.Header.Class.Type == EVENT_TRACE_TYPE_START) {
  566. status = CreateTraceInstanceId(
  567. (PVOID) TraceGuidReg[0].RegHandle,
  568. & InstInfo);
  569. if (status != ERROR_SUCCESS) {
  570. fprintf(stderr,
  571. "CreatTraceInstanceId() status=%d, %s\n",
  572. status, DecodeStatus(status)
  573. );
  574. return;
  575. }
  576. }
  577. status = TraceEventInstance(
  578. LoggerHandle,
  579. (PEVENT_INSTANCE_HEADER) & UserInstanceEvent,
  580. & InstInfo,
  581. NULL);
  582. break;
  583. case TYPE_USER_EVENT:
  584. UserEvent.EventInfo = InterlockedIncrement(&EventCount);
  585. status = TraceEvent(
  586. LoggerHandle,
  587. (PEVENT_TRACE_HEADER) & UserEvent);
  588. break;
  589. case TYPE_MOF_EVENT:
  590. UserMofEvent.Header.Flags |= WNODE_FLAG_USE_MOF_PTR;
  591. mofField = (PMOF_FIELD) & UserMofEvent.mofData;
  592. if (UserMofEvent.Header.Class.Type == 2) {
  593. mofField->DataPtr = (ULONGLONG) (&ise);
  594. mofField->Length = sizeof(INTEGER_SAMPLE_EVENT);
  595. }
  596. else if (UserMofEvent.Header.Class.Type == 3) {
  597. mofField->DataPtr = (ULONGLONG) (&fse);
  598. mofField->Length = sizeof(FLOAT_SAMPLE_EVENT);
  599. }
  600. else if (UserMofEvent.Header.Class.Type == 4) {
  601. mofField->DataPtr = (ULONGLONG) (&ase);
  602. mofField->Length = sizeof(ARRAY_SAMPLE_EVENT);
  603. }
  604. else {
  605. mofField->DataPtr = (ULONGLONG) (sse);
  606. mofField->Length = nStrEventSize;
  607. }
  608. if (bUseNullPtr)
  609. mofField->DataPtr = (ULONGLONG) (NULL);
  610. if (bIncorrect)
  611. mofField->Length += 1000;
  612. status = TraceEvent(
  613. LoggerHandle,
  614. (PEVENT_TRACE_HEADER) & UserMofEvent);
  615. if (status != ERROR_SUCCESS) {
  616. fprintf(stderr, "Error(%d) while writing event.\n", status);
  617. }
  618. break;
  619. default:
  620. status = ERROR_SUCCESS;
  621. break;
  622. }
  623. // logger buffers out of memory should not prevent provider from
  624. // generating events. This will only cause events lost.
  625. //
  626. if (status == ERROR_NOT_ENOUGH_MEMORY) {
  627. status = ERROR_SUCCESS;
  628. }
  629. if (status != ERROR_SUCCESS) {
  630. _ftprintf(stderr, _T("\nError %s while writing event\n"),
  631. DecodeStatus(status));
  632. _ftprintf( stderr, _T("Use GUID to disable Logger\n"));
  633. _ftprintf( stderr, _T("Logging Terminated\n"));
  634. return;
  635. }
  636. i++;
  637. if (i >= MaxEvents)
  638. break;
  639. if (!(i % 100))
  640. _tprintf(_T("."));
  641. _sleep(1);
  642. }
  643. }
  644. LPTSTR
  645. GuidToString(
  646. LPTSTR s,
  647. LPGUID piid
  648. )
  649. /*++
  650. Routine Description:
  651. Converts a GUID into a string.
  652. Arguments:
  653. s - String that will have the converted GUID.
  654. piid - GUID
  655. Return Value:
  656. None.
  657. --*/
  658. {
  659. _stprintf(s, _T("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"),
  660. piid->Data1,
  661. piid->Data2,
  662. piid->Data3,
  663. piid->Data4[0],
  664. piid->Data4[1],
  665. piid->Data4[2],
  666. piid->Data4[3],
  667. piid->Data4[4],
  668. piid->Data4[5],
  669. piid->Data4[6],
  670. piid->Data4[7]);
  671. return(s);
  672. }