home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / msconf / cnftest / util.c < prev   
Encoding:
C/C++ Source or Header  |  1996-07-03  |  17.9 KB  |  716 lines

  1. /* ----------------------------------------------------------------------
  2.  
  3.     CNFTEST sample for Microsoft ActiveX Conferencing
  4.  
  5.     Unpublished work.
  6.     Copyright (c) 1996, Microsoft Corporation
  7.     All rights reserved.
  8.  
  9.  
  10.     util.c
  11.  
  12.     Generic utility routines not specific to this application
  13.  
  14. ---------------------------------------------------------------------- */
  15.  
  16. #include "main.h"
  17. #include "shlobj.h"
  18.  
  19. static char _szAppName[] = "CnfTest";
  20. static char _szIniName[] = "CnfTest.ini";
  21.  
  22.  
  23.  
  24. /*  D I S P A T C H  M S G */
  25. /*-------------------------------------------------------------------------
  26.     %%Function: DispatchMsg
  27.  
  28.     Search the message table and call the appropriate routine.
  29. -------------------------------------------------------------------------*/
  30. LRESULT DispatchMsg(LPMSD lpmsd, HWND hwnd, UINT uMsg, WPARAM wparam, LPARAM lparam)
  31. {
  32.     for (; ; lpmsd++) {
  33.         if ((lpmsd->uMsg == 0) || (lpmsd->uMsg == uMsg)) {
  34.             return lpmsd->pfnmsg(hwnd, uMsg, wparam, lparam);
  35.         }
  36.     }
  37.  
  38.     NotReached();
  39. }
  40.  
  41.  
  42. /*  D I S P A T C H  C M D */
  43. /*-------------------------------------------------------------------------
  44.     %%Function: DispatchCmd
  45.  
  46.     Search the command table and call the appropriate routine.
  47. -------------------------------------------------------------------------*/
  48. LRESULT DispatchCmd(LPCMD lpcmd, HWND hwnd, WPARAM wparam, LPARAM lparam)
  49. {
  50.     WORD wCmd = GET_WM_COMMAND_ID(wparam, lparam);
  51.  
  52.     for (; ; lpcmd++) {
  53.         if ((lpcmd->wCmd == 0) || (lpcmd->wCmd == wCmd)) {
  54.             lpcmd->pfncmd(hwnd, wCmd,
  55.                     GET_WM_COMMAND_CMD(wparam, lparam),
  56.                     GET_WM_COMMAND_HWND(wparam, lparam));
  57.             break;
  58.         }
  59.     }
  60.  
  61.     return 0L;
  62. }
  63.  
  64.  
  65. /*  G E T  I N I  B O O L */
  66. /*-------------------------------------------------------------------------
  67.     %%Function: GetIniBool
  68.  
  69.     Get the boolean data for an entry
  70. -------------------------------------------------------------------------*/
  71. BOOL GetIniBool(LPSTR szEntry, BOOL fDefault)
  72. {
  73.     return GetPrivateProfileInt(_szAppName, szEntry, fDefault, _szIniName) != 0;
  74. }
  75.  
  76. /*  G E T  I N I  I N T */
  77. /*-------------------------------------------------------------------------
  78.     %%Function: GetIniInt
  79.  
  80.     Get the numeric data for an entry
  81. -------------------------------------------------------------------------*/
  82. DWORD GetIniInt(LPSTR szEntry, DWORD dwDefault)
  83. {
  84.     return GetPrivateProfileInt(_szAppName, szEntry, dwDefault, _szIniName);
  85. }
  86.  
  87. /*  G E T  I N I  S T R */
  88. /*-------------------------------------------------------------------------
  89.     %%Function: GetIniStr
  90.  
  91.     Get the string data for an entry
  92. -------------------------------------------------------------------------*/
  93. LPSTR GetIniStr(LPSTR szEntry, LPSTR szDefault)
  94. {
  95.     int    cch;
  96.     LPVOID lpv;
  97.     char   sz[MAX_PATH];
  98.  
  99.     cch = GetPrivateProfileString(_szAppName, szEntry, szDefault, sz, MAX_PATH, _szIniName);
  100.     if (cch == 0)
  101.     {
  102.         if (NULL == szDefault)
  103.             return NULL;
  104.  
  105.         cch = lstrlen(szDefault);
  106.         lstrcpy(sz, szDefault);
  107.     }
  108.     cch++; // include chNull
  109.  
  110.     lpv = LpvAlloc(cch);
  111.     if (lpv == NULL)
  112.         return NULL;
  113.  
  114.     lstrcpyn(lpv, sz, cch);
  115.  
  116.     return lpv;
  117. }
  118.  
  119.  
  120. /* G E T  I N I  H E X */
  121. /*-------------------------------------------------------------------------
  122.     %%Function: GetIniHex
  123.  
  124.     Convert the hex data into binary.
  125.     If no entry is found, lpv isn't modified
  126. -------------------------------------------------------------------------*/
  127. VOID GetIniHex(LPSTR szEntry, LPVOID lpv, int cb)
  128. {
  129.     char sz[MAX_PATH];
  130.  
  131.     if (GetPrivateProfileString(_szAppName, szEntry, lpNil, sz, MAX_PATH, _szIniName) != 0) {
  132.         HexToData(sz, lpv, cb);
  133.     }
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140. /*  W R I T E  I N I  S T R */
  141. /*-------------------------------------------------------------------------
  142.     %%Function: WriteIniStr
  143.  
  144.     Write the data to an entry in the ini file
  145. -------------------------------------------------------------------------*/
  146. VOID WriteIniStr(LPSTR szEntry, LPSTR szData)
  147. {
  148.     WritePrivateProfileString(_szAppName, szEntry, szData, _szIniName);
  149. }
  150.  
  151.  
  152. /*  W R I T E  I N I  I N T */
  153. /*-------------------------------------------------------------------------
  154.     %%Function: WriteIniInt
  155.  
  156.     Write the numeric data to an entry in the ini file
  157. -------------------------------------------------------------------------*/
  158. VOID WriteIniInt(LPSTR szEntry, DWORD dw)
  159. {
  160.     char szData[32];
  161.  
  162.     wsprintf(szData, "%d", dw);
  163.     WritePrivateProfileString(_szAppName, szEntry, szData, _szIniName);
  164. }
  165.  
  166.  
  167.  
  168. /*  W R I T E  I N I  B O O L */
  169. /*-------------------------------------------------------------------------
  170.     %%Function: WriteIniBool
  171.  
  172.     Write the boolean value to an entry in the registery
  173. -------------------------------------------------------------------------*/
  174. VOID WriteIniBool(LPSTR szEntry, BOOL f)
  175. {
  176.     WritePrivateProfileString(_szAppName, szEntry, f ? "1" : "0", _szIniName);
  177. }
  178.  
  179.  
  180. /* W R I T E  I N I  H E X */
  181. /*-------------------------------------------------------------------------
  182.     %%Function: WriteIniHex
  183.  
  184. -------------------------------------------------------------------------*/
  185. VOID WriteIniHex(LPSTR szEntry, LPVOID lpv, int cb)
  186. {
  187.     char   sz[MAX_PATH];
  188.  
  189.     DataToHex(lpv, sz, cb);
  190.  
  191.     WriteIniStr(szEntry, sz);
  192. }
  193.  
  194.  
  195. /*  C E N T E R  W I N D O W */
  196. /*-------------------------------------------------------------------------
  197.     %%Function: CenterWindow
  198.  
  199.     Center a window over another window.
  200. -------------------------------------------------------------------------*/
  201. VOID CenterWindow(HWND hwndChild, HWND hwndParent)
  202. {
  203.     int   xNew, yNew;
  204.     int   cxChild, cyChild;
  205.     int   cxParent, cyParent;
  206.     int   cxScreen, cyScreen;
  207.     RECT  rcChild, rcParent;
  208.     HDC   hdc;
  209.  
  210.     // Get the Height and Width of the child window
  211.     GetWindowRect(hwndChild, &rcChild);
  212.     cxChild = rcChild.right - rcChild.left;
  213.     cyChild = rcChild.bottom - rcChild.top;
  214.  
  215.     // Get the Height and Width of the parent window
  216.     GetWindowRect(hwndParent, &rcParent);
  217.     cxParent = rcParent.right - rcParent.left;
  218.     cyParent = rcParent.bottom - rcParent.top;
  219.  
  220.     // Get the display limits
  221.     hdc = GetDC(hwndChild);
  222.     if (hdc == NULL) {
  223.         // major problems - move window to 0,0
  224.         xNew = yNew = 0;
  225.     } else {
  226.         cxScreen = GetDeviceCaps(hdc, HORZRES);
  227.         cyScreen = GetDeviceCaps(hdc, VERTRES);
  228.         ReleaseDC(hwndChild, hdc);
  229.  
  230.         if (hwndParent == hwndNil) {
  231.             cxParent = cxScreen;
  232.             cyParent = cyScreen;
  233.             SetRect(&rcParent, 0, 0, cxScreen, cyScreen);
  234.         }
  235.  
  236.         // Calculate new X position, then adjust for screen
  237.         xNew = rcParent.left + ((cxParent - cxChild) / 2);
  238.         if (xNew < 0) {
  239.             xNew = 0;
  240.         } else if ((xNew + cxChild) > cxScreen) {
  241.             xNew = cxScreen - cxChild;
  242.         }
  243.  
  244.         // Calculate new Y position, then adjust for screen
  245.         yNew = rcParent.top  + ((cyParent - cyChild) / 2);
  246.         if (yNew < 0) {
  247.             yNew = 0;
  248.         } else if ((yNew + cyChild) > cyScreen) {
  249.             yNew = cyScreen - cyChild;
  250.         }
  251.  
  252.     }
  253.  
  254.     SetWindowPos(hwndChild, NULL, xNew, yNew,    0, 0,
  255.         SWP_NOSIZE | SWP_NOZORDER);
  256. }
  257.  
  258.  
  259. /*  L P V  A  L L O C */
  260. /*-------------------------------------------------------------------------
  261.     %%Function: LpvAlloc
  262.  
  263.     Return a pointer to an allocated array of bytes
  264. -------------------------------------------------------------------------*/
  265. LPVOID LpvAlloc(int cb)
  266. {
  267.     return LocalAlloc(LMEM_FIXED, cb);
  268. }
  269.  
  270.  
  271. /*  F R E E  P L P V */
  272. /*-------------------------------------------------------------------------
  273.     %%Function: FreePlpv
  274.  
  275.     Free the data pointed to by plpv and set *plpv to NULL
  276. -------------------------------------------------------------------------*/
  277. VOID FreePlpv(LPVOID plpv)
  278. {
  279.     if ((plpv == NULL) || (*(VOID FAR * FAR *)plpv == NULL)) {
  280.         return;
  281.     }
  282.  
  283.     LocalFree(*(VOID FAR * FAR *)plpv);
  284.     *(VOID FAR * FAR *)plpv = NULL;
  285. }
  286.  
  287.  
  288. /*  D E F  C M D  P R O C */
  289. /*-------------------------------------------------------------------------
  290.     %%Function: DefCmdProc
  291.  
  292.     Default command procedure.
  293. -------------------------------------------------------------------------*/
  294. VOID DefCmdProc(HWND hwnd, WORD wCmd, WORD w2, HWND hwndCtrl)
  295. {
  296.     Log2(LOG_NORMAL, "DefCmdProc reached: wCmd=0x%08X, w2=0x%08X", wCmd, w2);
  297. }
  298.  
  299.  
  300.  
  301. /*  C H  F R O M  H E X */
  302. /*-------------------------------------------------------------------------
  303.     %%Function: ChFromHex
  304.  
  305.     Convert from Hex data to ascii character
  306. -------------------------------------------------------------------------*/
  307. char ChFromHex(LPSTR lpch)
  308. {
  309.     int i = 0;
  310.     int cch = 2;
  311.     char ch;
  312.  
  313.     while (cch-- > 0) {
  314.         ch = *lpch++;
  315.         if (ch >= 'A') {
  316.             i = (i*16) + (ch - ('A'-10));
  317.         } else {
  318.             i = (i*16) + (ch - '0');
  319.         }
  320.     }
  321.  
  322.     return (char) i;
  323. }
  324.  
  325.  
  326. /*  H E X  T O  D A T A */
  327. /*-------------------------------------------------------------------------
  328.     %%Function: HexToData
  329.  
  330.     Convert from Hex data to ascii character
  331. -------------------------------------------------------------------------*/
  332. VOID HexToData(LPSTR lpchSrc, LPVOID lpvDest, int cb)
  333. {
  334.     CHAR * lpchDest = lpvDest;
  335.  
  336.     CharUpperBuff(lpchSrc, cb);
  337.  
  338.     while (cb-- > 0)
  339.     {
  340.         *lpchDest++ = ChFromHex(lpchSrc);
  341.         lpchSrc += 2;
  342.     }
  343. }
  344.  
  345.  
  346. /*  H E X  T O  B I N */
  347. /*-------------------------------------------------------------------------
  348.     %%Function: HexToBin
  349.  
  350.     Convert from Hex data to ascii character
  351. -------------------------------------------------------------------------*/
  352. LPSTR HexToBin(LPSTR lpchSrc, LPVOID lpvDest, int cb)
  353. {
  354.     CHAR * lpchDest = ((CHAR *) lpvDest) + cb;
  355.  
  356.     CharUpperBuff(lpchSrc, cb);
  357.  
  358.     while (cb-- > 0)
  359.     {
  360.         lpchDest--;
  361.         *lpchDest = ChFromHex(lpchSrc);
  362.         lpchSrc += 2;
  363.     }
  364.     return lpchSrc;
  365. }
  366.  
  367.  
  368. /*  D A T A  T O  H E X */
  369. /*-------------------------------------------------------------------------
  370.     %%Function: DataToHex
  371.  
  372. -------------------------------------------------------------------------*/
  373. VOID DataToHex(LPSTR lpchSrc, LPSTR lpchDest, int cb)
  374. {
  375.     unsigned char ch;
  376.  
  377.     if (lpchSrc == lpNil)
  378.     {
  379. //        Log(LOG_ALWAYS, "DataToHex - lpSrc == lpNil");
  380.         SetEmptySz(lpchDest);
  381.         return;
  382.     }
  383.  
  384.     while (cb-- > 0) {
  385.         ch = 0x00FF & (unsigned char) (*lpchSrc++);
  386.         wsprintf(lpchDest, "%02X", ch);
  387.         lpchDest += 2;
  388.     }
  389. }
  390.  
  391.  
  392.  
  393.  
  394. /* S E T  M E N U  C H E C K */
  395. /*----------------------------------------------------------------------------
  396.     %%Function: SetMenuCheck
  397.  
  398.     Set the menu item's check mark.
  399.  
  400. ----------------------------------------------------------------------------*/
  401. VOID SetMenuCheck(UINT idm, BOOL fCheck)
  402. {
  403.     CheckMenuItem(ghMenu, idm,
  404.         fCheck ? (MF_CHECKED  | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND));
  405. }
  406.  
  407.  
  408.  
  409. /* M A Y B E   D E L E T E   O B J E C T */
  410. /*----------------------------------------------------------------------------
  411.     %%Function: MaybeDeleteObject
  412.  
  413.     Check usage count, delete if we can
  414. ----------------------------------------------------------------------------*/
  415. VOID MaybeDeleteObject(HGDIOBJ * phgdi)
  416. {
  417.     if (*phgdi == hgdiNil)
  418.         return;
  419.  
  420.     DeleteObject(*phgdi);
  421.     *phgdi = hgdiNil;    
  422. }
  423.  
  424.  
  425. static char _szAssertTitle[] = "CnfTest Assert";
  426.  
  427.  
  428. /*  A S S E R T  P R O C */
  429. /*-------------------------------------------------------------------------
  430.     %%Function: AssertProc
  431.  
  432. -------------------------------------------------------------------------*/
  433. VOID FAR PASCAL AssertProc(LPSTR lpszMsg, LPSTR lpszAssert, LPSTR lpszFile, UINT line)
  434. {
  435.     char szBuffer[MAX_PATH];
  436.     int  id;
  437.     static BOOL _fInAssert = fFalse;
  438.  
  439.     wsprintf((LPSTR)szBuffer,
  440.         "Assert: %s\nFile %s, Line %d",
  441.         (lpszMsg && *lpszMsg) ? lpszMsg  : lpszAssert,
  442.         lpszFile ? lpszFile : "", line);
  443.  
  444.     OutputDebugString(szBuffer);
  445.  
  446.     if (_fInAssert) {
  447.         return;
  448.     }
  449.     _fInAssert = fTrue;
  450.  
  451.     do {
  452.         id = MessageBox(NULL, (LPSTR)szBuffer, (LPSTR)_szAssertTitle,
  453.                     MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL);
  454.  
  455.         switch (id)
  456.         {
  457.         case IDRETRY:
  458.             DebugBreak();
  459.             break;
  460.         case IDABORT:
  461.             FatalAppExit(0, (LPSTR)szBuffer);
  462.             break;
  463.         case IDIGNORE:
  464.         default:
  465.             break;
  466.         }
  467.     } while (id == IDRETRY);
  468.  
  469.     _fInAssert = fFalse;
  470. }
  471.  
  472.  
  473. /*  L O G */
  474. /*-------------------------------------------------------------------------
  475.     %%Function: Log
  476.  
  477. -------------------------------------------------------------------------*/
  478. VOID Log(DWORD grf, LPSTR lpsz)
  479. {
  480.     int i;
  481.  
  482.     if (((grf & gPref.grfLog) == 0) || (ghwndMsg == hwndNil))
  483.     {
  484.         return;
  485.     }
  486.  
  487.     // write the string to the Message window
  488.     i = SendMessage(ghwndMsg, LB_ADDSTRING, 0, (LPARAM) lpsz);
  489.     if( grf == LOG_ERROR )
  490.         SendMessage(ghwndMsg, LB_SETITEMDATA, (WPARAM)i, (LPARAM)255);
  491.     else
  492.         SendMessage(ghwndMsg, LB_SETITEMDATA, (WPARAM)i, (LPARAM)0);
  493.  
  494.     PostMessage(ghwndMsg, WM_VSCROLL, SB_BOTTOM, 0);
  495. }
  496.  
  497.  
  498. /* C L E A R  L O G */
  499. /*----------------------------------------------------------------------------
  500.     %%Function: ClearLog
  501.  
  502.     Clear the log screen
  503.  
  504. ----------------------------------------------------------------------------*/
  505. VOID ClearLog(void)
  506. {
  507.     SendMessage(ghwndMsg, LB_RESETCONTENT, 0, 0);
  508. }
  509.  
  510. /* L O G  T E S T  S T A R T */
  511. /*----------------------------------------------------------------------------
  512.     %%Function: LogTestStart
  513.  
  514.     Start a test by clearing the log and displaying the string.
  515.  
  516. ----------------------------------------------------------------------------*/
  517. VOID LogTestStart(LPSTR sz)
  518. {
  519.     Log1(LOG_ALWAYS, "==> Running Test %s", sz);
  520. }
  521.  
  522.  
  523. /*  L O G  T E S T  S T O P */
  524. /*----------------------------------------------------------------------------
  525.     %%Function: LogTestStop
  526.  
  527. ----------------------------------------------------------------------------*/
  528. VOID LogTestStop(LPSTR sz)
  529. {
  530.     Log1(LOG_ALWAYS, "==> Test %s Complete", sz);
  531. }
  532.  
  533. /*  L O G  T E S T  C A N C E L */
  534. /*----------------------------------------------------------------------------
  535.     %%Function: LogTestCancel
  536.  
  537. ----------------------------------------------------------------------------*/
  538. VOID LogTestCancel(LPSTR sz)
  539. {
  540.     Log1(LOG_ALWAYS, "==> Test %s Canceled", sz);
  541. }
  542.  
  543.  
  544. /*  L O G  R E S U L T */
  545. /*----------------------------------------------------------------------------
  546.     %%Function: LogResult
  547.  
  548. ----------------------------------------------------------------------------*/
  549. VOID LogResult(LPSTR sz, DWORD dwTest, DWORD dwResult)
  550. {
  551.     Log3((dwResult == CONFERR_SUCCESS ? LOG_NORMAL : LOG_ERROR), "%s Test %d Result=%s", sz, dwTest, GetConferrString(dwResult));
  552. }
  553.  
  554.  
  555. static char _szFilter[] = "All Files\0*.*\0Text Files (*.txt)\0*.TXT\0";
  556.  
  557.  
  558.  
  559. /*  F  G E T  F I L E  N A M E */
  560. /*----------------------------------------------------------------------------
  561.     %%Function: FGetFileName
  562.  
  563. ----------------------------------------------------------------------------*/
  564. BOOL FGetFileName(LPSTR szFileName)
  565. {
  566.     OPENFILENAME ofn;
  567.  
  568.     SetEmptySz(szFileName);
  569.     ClearStruct(&ofn);
  570.  
  571.     ofn.lStructSize   = sizeof(OPENFILENAME);
  572.     ofn.hwndOwner     = ghwndMain;
  573.     ofn.hInstance     = (HANDLE) ghInst;
  574.     ofn.lpstrFilter   = _szFilter;
  575.     ofn.nFilterIndex  = 1L;
  576.     ofn.lpstrFile     = (LPSTR) szFileName;
  577.     ofn.nMaxFile      = MAX_PATH; // really sizeof(szFileName)
  578.     ofn.lpstrTitle    = "Pick a file to send";
  579.     ofn.lpstrInitialDir = NULL;
  580.     ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER;
  581.  
  582.     if (!GetOpenFileName(&ofn))
  583.         return fFalse;
  584.  
  585.     return fTrue;
  586. }
  587.  
  588.  
  589.  
  590. /*  F  G E T  D I R E C T O R Y */
  591. /*----------------------------------------------------------------------------
  592.     %%Function: FGetDirectory
  593.  
  594. ----------------------------------------------------------------------------*/
  595. BOOL FGetDirectory(LPSTR szDir)
  596. {
  597.     BOOL  fRet;
  598.     CHAR  szPath[MAX_PATH];
  599.     LPITEMIDLIST pidl;
  600.     LPITEMIDLIST pidlRoot;
  601.     LPMALLOC lpMalloc;
  602.  
  603.     BROWSEINFO bi = {
  604.         ghwndMain,
  605.         NULL,
  606.         szPath,
  607.         "Select a Directory",
  608.         BIF_RETURNONLYFSDIRS,
  609.         NULL, 0L, 0    };
  610.  
  611.     if (0 != SHGetSpecialFolderLocation(HWND_DESKTOP, CSIDL_DRIVES, &pidlRoot))
  612.         return fFalse;
  613.     if (NULL == pidlRoot)
  614.         return fFalse;
  615.  
  616.     bi.pidlRoot = pidlRoot;
  617.     pidl = SHBrowseForFolder(&bi);
  618.  
  619.     if (NULL != pidl)
  620.         fRet = SHGetPathFromIDList(pidl, szDir);
  621.     else
  622.         fRet = fFalse;
  623.  
  624.     // Get the shell's allocator to free PIDLs
  625.     if (!SHGetMalloc(&lpMalloc) && (NULL != lpMalloc))
  626.     {
  627.         if (NULL != pidlRoot)
  628.         {
  629.             lpMalloc->lpVtbl->Free(lpMalloc, pidlRoot);
  630.         }
  631.  
  632.         if (NULL != pidl)
  633.         {
  634.             lpMalloc->lpVtbl->Free(lpMalloc, pidl);
  635.         }
  636.  
  637.         lpMalloc->lpVtbl->Release(lpMalloc);
  638.     }
  639.  
  640.     return fRet;
  641. }
  642.  
  643.  
  644.  
  645. /*  G E T  R A D I O  B U T T O N */
  646. /*----------------------------------------------------------------------------
  647.     %%Function: GetRadioButton
  648.  
  649. ----------------------------------------------------------------------------*/
  650. int GetRadioButton(HWND hdlg, int idrFirst, int idrLast)
  651. {
  652.     int id;
  653.  
  654.     for (id = idrFirst; id <= idrLast; id++)
  655.     {
  656.         if (IsDlgButtonChecked(hdlg, id))
  657.             return id;
  658.     }
  659.     return idrFirst;
  660. }
  661.  
  662.  
  663. /*  G U I D  T O  S Z */
  664. /*----------------------------------------------------------------------------
  665.     %%Function: GuidToSz
  666.  
  667.     Convert the guid to a hex string.
  668.     Assumes lpchDest has space for at least sizeof(GUID)*2+1 chars.
  669.  
  670.     Note the difference between this and UuidToString (or StringFromGUID2)
  671. ----------------------------------------------------------------------------*/
  672. VOID GuidToSz(GUID * pguid, LPSTR lpchDest)
  673. {
  674.     int i;
  675.  
  676.     ASSERT(NULL != pguid);
  677.     ASSERT(NULL != lpchDest);
  678.  
  679.     lstrcpy(lpchDest, "--------------------------------");
  680.  
  681.     wsprintf(lpchDest, "%08X%04X%04X", pguid->Data1, pguid->Data2, pguid->Data3);
  682.     lpchDest += 8+4+4;
  683.     for (i = 0; i < 8; i++)
  684.     {
  685.         wsprintf(lpchDest, "%02X", pguid->Data4[i]);
  686.         lpchDest += 2;
  687.     }
  688. }
  689.  
  690.  
  691. /*  S Z  T O  G U I D */
  692. /*----------------------------------------------------------------------------
  693.     %%Function: SzToGuid
  694.  
  695. ----------------------------------------------------------------------------*/
  696. VOID SzToGuid(LPSTR lpchSrc, GUID * pguid)
  697. {
  698.     if (FEmptySz(lpchSrc) || (CchSz(lpchSrc) < sizeof(GUID)*2))
  699.     {
  700.         ClearStruct(pguid);
  701.         return;
  702.     }
  703.  
  704.     ClearStruct(pguid);
  705.  
  706.     lpchSrc = HexToBin(lpchSrc, &pguid->Data1, sizeof(pguid->Data1));
  707.     lpchSrc = HexToBin(lpchSrc, &pguid->Data2, sizeof(pguid->Data2));
  708.     lpchSrc = HexToBin(lpchSrc, &pguid->Data3, sizeof(pguid->Data3));
  709.     HexToData(lpchSrc, pguid->Data4, sizeof(pguid->Data4));
  710. }
  711.     
  712.  
  713.  
  714.  
  715.  
  716.