home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 39 / IOPROG_39.ISO / SOFT / sdkjava40.exe / data1.cab / fg_Samples / Samples / COM / jexegen / stub / util.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-04  |  1.8 KB  |  78 lines

  1. /*++
  2.  
  3. Copyright (c) 1999  Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     util.cpp
  8.  
  9. Abstract:
  10.  
  11.     utility methods.
  12.  
  13. --*/
  14.  
  15. #pragma warning(disable:4514)   // "unreferenced inline function" warning
  16.  
  17. #pragma warning(disable:4201)   // "nameless struct/union" warning
  18. #include <windows.h>
  19. #pragma warning(default:4201)   // "nameless struct/union" warning
  20.  
  21.  
  22. //------------------------------------------------------------------------------
  23. // GUID2StringA()
  24. //
  25. // Utility function: convert a GUID into the ANSI string representation.
  26. //------------------------------------------------------------------------------
  27. VOID
  28. GUID2StringA(
  29.     REFGUID rguid,
  30.     LPSTR   lpsz )
  31. {
  32.     int i;
  33.     LPSTR p = lpsz;
  34.     static const CHAR szDigits[] = "0123456789ABCDEF";
  35.     static const BYTE GuidMap[] = { 3, 2, 1, 0, '-', 5, 4, '-', 7, 6, '-',
  36.                                     8, 9, '-', 10, 11, 12, 13, 14, 15 };
  37.  
  38.     const BYTE * pBytes = (const BYTE *)&rguid;
  39.  
  40.     *p++ = '{';
  41.  
  42.     for (i = 0; i < sizeof(GuidMap); i++)
  43.     {
  44.         if (GuidMap[i] == '-')
  45.         {
  46.             *p++ = '-';
  47.         }
  48.         else
  49.         {
  50.             *p++ = szDigits[ (pBytes[GuidMap[i]] & 0xF0) >> 4 ];
  51.             *p++ = szDigits[ (pBytes[GuidMap[i]] & 0x0F) ];
  52.         }
  53.     }
  54.     *p++ = '}';
  55.     *p   = '\0';
  56. }
  57.  
  58.  
  59.  
  60. //------------------------------------------------------------------------------
  61. // AnsiTranslateChars()
  62. //
  63. // NB: chFrom cannot be any character that can be a lead byte.
  64. //------------------------------------------------------------------------------
  65. VOID AnsiTranslateChars(LPSTR psz,CHAR chFrom,CHAR chTo)
  66. {
  67.     if( psz != NULL )
  68.     {
  69.         while( *psz )
  70.         {
  71.             if ( *psz == chFrom )
  72.                 *psz = chTo;
  73.  
  74.             psz = CharNext(psz);
  75.         }
  76.     }
  77. }
  78.