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.

156 lines
3.4 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORP., 1993-1995
  4. * TITLE: USBUTIL.CPP
  5. * VERSION: 1.0
  6. * AUTHOR: jsenior
  7. * DATE: 10/28/1998
  8. *
  9. ********************************************************************************
  10. *
  11. * CHANGE LOG:
  12. *
  13. * DATE REV DESCRIPTION
  14. * ---------- ------- ----------------------------------------------------------
  15. * 10/28/1998 jsenior Original implementation.
  16. *
  17. *******************************************************************************/
  18. #include "usbutil.h"
  19. extern HINSTANCE gHInst;
  20. BOOL
  21. SetTextItem (HWND hWnd,
  22. int ControlItem,
  23. TCHAR *s)
  24. {
  25. HWND control;
  26. if (NULL == (control = GetDlgItem(hWnd, ControlItem))) {
  27. return FALSE;
  28. }
  29. return SetWindowText(control, s);
  30. }
  31. BOOL
  32. SetTextItem (HWND hWnd,
  33. int ControlItem,
  34. int StringItem)
  35. {
  36. TCHAR buf[1000];
  37. if ( !LoadString(gHInst, StringItem, buf, 1000)) {
  38. return FALSE;
  39. }
  40. return SetTextItem(hWnd, ControlItem, buf);
  41. }
  42. /*
  43. * strToGUID
  44. *
  45. * converts a string in the form xxxxxxxx-xxxx-xxxx-xx-xx-xx-xx-xx-xx-xx-xx
  46. * {36FC9E60-C465-11CF-8056-444553540000}
  47. * into a guid
  48. */
  49. BOOL StrToGUID( LPSTR str, GUID * pguid )
  50. {
  51. int idx;
  52. LPSTR ptr;
  53. LPSTR next;
  54. DWORD data;
  55. DWORD mul;
  56. BYTE ch;
  57. BOOL done;
  58. int count;
  59. idx = 0;
  60. done = FALSE;
  61. if (*str == '{') {
  62. str++;
  63. }
  64. while( !done )
  65. {
  66. /*
  67. * find the end of the current run of digits
  68. */
  69. ptr = str;
  70. if (idx < 3 || idx == 4) {
  71. while( (*str) != '-' && (*str) != 0 ) {
  72. str++;
  73. }
  74. if( *str == 0 || *str == '}') {
  75. done = TRUE;
  76. } else {
  77. next = str+1;
  78. }
  79. } else if (idx == 3 || idx > 4) {
  80. for( count = 0; (*str) != 0 && count < 2; count++ ) {
  81. str++;
  82. }
  83. if( *str == 0 || *str == '}') {
  84. done = TRUE;
  85. } else {
  86. next = str;
  87. }
  88. }
  89. /*
  90. * scan backwards from the end of the string to the beginning,
  91. * converting characters from hex chars to numbers as we go
  92. */
  93. str--;
  94. mul = 1;
  95. data = 0;
  96. while(str >= ptr) {
  97. ch = *str;
  98. if( ch >= 'A' && ch <= 'F' ) {
  99. data += mul * (DWORD) (ch-'A'+10);
  100. } else if( ch >= 'a' && ch <= 'f' ) {
  101. data += mul * (DWORD) (ch-'a'+10);
  102. } else if( ch >= '0' && ch <= '9' ) {
  103. data += mul * (DWORD) (ch-'0');
  104. } else {
  105. return FALSE;
  106. }
  107. mul *= 16;
  108. str--;
  109. }
  110. /*
  111. * stuff the current number into the guid
  112. */
  113. switch( idx )
  114. {
  115. case 0:
  116. pguid->Data1 = data;
  117. break;
  118. case 1:
  119. pguid->Data2 = (WORD) data;
  120. break;
  121. case 2:
  122. pguid->Data3 = (WORD) data;
  123. break;
  124. default:
  125. pguid->Data4[ idx-3 ] = (BYTE) data;
  126. break;
  127. }
  128. /*
  129. * did we find all 11 numbers?
  130. */
  131. idx++;
  132. if( idx == 11 )
  133. {
  134. if( done ) {
  135. return TRUE;
  136. } else {
  137. return FALSE;
  138. }
  139. }
  140. str = next;
  141. }
  142. return FALSE;
  143. } /* strToGUID */