home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / workshop / prog / msconf / confsdk.exe / UTIL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-23  |  19.8 KB  |  789 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[cbMaxSz];
  98.  
  99.     cch = GetPrivateProfileString(_szAppName, szEntry, szDefault, sz, cbMaxSz, _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[cbMaxSz];
  130.  
  131.     if (GetPrivateProfileString(_szAppName, szEntry, lpNil, sz, cbMaxSz, _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[cbMaxSz];
  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. /*  E N S U R E  D I R  E X I S T S */
  302. /*-------------------------------------------------------------------------
  303.     %%Function: EnsureDirExists
  304.  
  305.     Ensure the Directory exists, creating it if necessary
  306.     Returns fFalse if there was a problem.
  307. -------------------------------------------------------------------------*/
  308. BOOL EnsureDirExists(LPSTR szDir)
  309. {
  310.     HANDLE hFile;
  311.  
  312.     hFile = CreateFile(szDir, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
  313.         NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  314.  
  315.     if (hFile != INVALID_HANDLE_VALUE) {
  316.         CloseHandle(hFile);
  317.         return fTrue;
  318.     }
  319.  
  320.     return CreateDirectory(szDir, NULL);
  321. }
  322.  
  323.  
  324.  
  325. /*  C H  F R O M  H E X */
  326. /*-------------------------------------------------------------------------
  327.     %%Function: ChFromHex
  328.  
  329.     Convert from Hex data to ascii character
  330. -------------------------------------------------------------------------*/
  331. char ChFromHex(LPSTR lpch)
  332. {
  333.     int i = 0;
  334.     int cch = 2;
  335.     char ch;
  336.  
  337.     while (cch-- > 0) {
  338.         ch = *lpch++;
  339.         if (ch >= 'A') {
  340.             i = (i*16) + (ch - ('A'-10));
  341.         } else {
  342.             i = (i*16) + (ch - '0');
  343.         }
  344.     }
  345.  
  346.     return (char) i;
  347. }
  348.  
  349.  
  350. /*  H E X  T O  D A T A */
  351. /*-------------------------------------------------------------------------
  352.     %%Function: HexToData
  353.  
  354.     Convert from Hex data to ascii character
  355. -------------------------------------------------------------------------*/
  356. VOID HexToData(LPSTR lpchSrc, LPVOID lpvDest, int cb)
  357. {
  358.     CHAR * lpchDest = lpvDest;
  359.  
  360.     CharUpperBuff(lpchSrc, cb);
  361.  
  362.     while (cb-- > 0)
  363.     {
  364.         *lpchDest++ = ChFromHex(lpchSrc);
  365.         lpchSrc += 2;
  366.     }
  367. }
  368.  
  369.  
  370. /*  H E X  T O  B I N */
  371. /*-------------------------------------------------------------------------
  372.     %%Function: HexToData
  373.  
  374.     Convert from Hex data to ascii character
  375. -------------------------------------------------------------------------*/
  376. LPSTR HexToBin(LPSTR lpchSrc, LPVOID lpvDest, int cb)
  377. {
  378.     CHAR * lpchDest = ((CHAR *) lpvDest) + cb;
  379.  
  380.     CharUpperBuff(lpchSrc, cb);
  381.  
  382.     while (cb-- > 0)
  383.     {
  384.         lpchDest--;
  385.         *lpchDest = ChFromHex(lpchSrc);
  386.         lpchSrc += 2;
  387.     }
  388.     return lpchSrc;
  389. }
  390.  
  391.  
  392. /*  D A T A  T O  H E X */
  393. /*-------------------------------------------------------------------------
  394.     %%Function: DataToHex
  395.  
  396. -------------------------------------------------------------------------*/
  397. VOID DataToHex(LPSTR lpchSrc, LPSTR lpchDest, int cb)
  398. {
  399.     unsigned char ch;
  400.  
  401.     if (lpchSrc == lpNil)
  402.     {
  403. //        Log(LOG_ALWAYS, "DataToHex - lpSrc == lpNil");
  404.         SetEmptySz(lpchDest);
  405.         return;
  406.     }
  407.  
  408.     while (cb-- > 0) {
  409.         ch = 0x00FF & (unsigned char) (*lpchSrc++);
  410.         wsprintf(lpchDest, "%02X", ch);
  411.         lpchDest += 2;
  412.     }
  413. }
  414.  
  415.  
  416.  
  417. /*  C H A N G E  D L G  I T E M  T E X T */
  418. /*-------------------------------------------------------------------------
  419.     %%Function: ChangeDlgItemText
  420.  
  421. -------------------------------------------------------------------------*/
  422. VOID ChangeDlgItemText(HWND hdlg, int id, LPSTR sz)
  423. {
  424.     RECT rc;
  425.  
  426.     if (sz == lpNil) {
  427.         return;
  428.     }
  429.  
  430.     SetDlgItemText(hdlg, id, sz);
  431.     GetWindowRect(GetDlgItem(hdlg, id), &rc);
  432.     MapWindowPoints(HWND_DESKTOP, hdlg, (LPPOINT) &rc, 2);
  433.     InvalidateRect(hdlg, &rc, fFalse);
  434. }
  435.  
  436.  
  437. /*  C H A N G E  D L G  I T E M  I N T */
  438. /*-------------------------------------------------------------------------
  439.     %%Function: ChangeDlgItemInt
  440.  
  441. -------------------------------------------------------------------------*/
  442. VOID ChangeDlgItemInt(HWND hdlg, int id, int i)
  443. {
  444.     RECT rc;
  445.  
  446.     SetDlgItemInt(hdlg, id, i, fFalse);
  447.     GetWindowRect(GetDlgItem(hdlg, id), &rc);
  448.     MapWindowPoints(HWND_DESKTOP, hdlg, (LPPOINT) &rc, 2);
  449.     InvalidateRect(hdlg, &rc, fFalse);
  450. }
  451.  
  452. /* S E T  D L G  B T N  F L A G */
  453. /*----------------------------------------------------------------------------
  454.     %%Function: SetDlgBtnFlag
  455.  
  456.     Set a flag based on the status of a dialog button.
  457.  
  458. ----------------------------------------------------------------------------*/
  459. VOID SetDlgBtnFlag(HWND hdlg, int id, LPDWORD lpdw, DWORD f)
  460. {
  461.     if (IsDlgButtonChecked(hdlg, id))
  462.         *lpdw |= f;
  463.     else
  464.         *lpdw &= ~f;
  465. }
  466.  
  467. /* S E T  M E N U  C H E C K */
  468. /*----------------------------------------------------------------------------
  469.     %%Function: SetMenuCheck
  470.  
  471.     Set the menu item's check mark.
  472.  
  473. ----------------------------------------------------------------------------*/
  474. VOID SetMenuCheck(UINT idm, BOOL fCheck)
  475. {
  476.     CheckMenuItem(ghMenu, idm,
  477.         fCheck ? (MF_CHECKED  | MF_BYCOMMAND) : (MF_UNCHECKED | MF_BYCOMMAND));
  478. }
  479.  
  480.  
  481.  
  482. /* M A Y B E   D E L E T E   O B J E C T */
  483. /*----------------------------------------------------------------------------
  484.     %%Function: MaybeDeleteObject
  485.  
  486.     Check usage count, delete if we can
  487. ----------------------------------------------------------------------------*/
  488. VOID MaybeDeleteObject(HGDIOBJ * phgdi)
  489. {
  490.     if (*phgdi == hgdiNil)
  491.         return;
  492.  
  493.     DeleteObject(*phgdi);
  494.     *phgdi = hgdiNil;    
  495. }
  496.  
  497.  
  498. static char _szAssertTitle[] = "CnfTest Assert";
  499.  
  500.  
  501. /*  A S S E R T  P R O C */
  502. /*-------------------------------------------------------------------------
  503.     %%Function: AssertProc
  504.  
  505. -------------------------------------------------------------------------*/
  506. VOID FAR PASCAL AssertProc(LPSTR lpszMsg, LPSTR lpszAssert, LPSTR lpszFile, UINT line)
  507. {
  508.     char szBuffer[cbMaxSz];
  509.     int  id;
  510.     static BOOL _fInAssert = fFalse;
  511.  
  512.     wsprintf((LPSTR)szBuffer,
  513.                "Assert: %s\nFile %s, Line %d",
  514.             (lpszMsg && *lpszMsg) ? lpszMsg  : lpszAssert,
  515.             lpszFile ? lpszFile : "",
  516.             line);
  517.  
  518.     OutputDebugString(szBuffer);
  519.  
  520.     if (_fInAssert) {
  521.         return;
  522.     }
  523.     _fInAssert = fTrue;
  524.  
  525.     do {
  526.         id = MessageBox(NULL, (LPSTR)szBuffer, (LPSTR)_szAssertTitle,
  527.                     MB_ICONHAND | MB_ABORTRETRYIGNORE | MB_SYSTEMMODAL);
  528.  
  529.         switch (id)
  530.         {
  531.         case IDRETRY:
  532.             DebugBreak();
  533.             break;
  534.         case IDABORT:
  535.             FatalAppExit(0, (LPSTR)szBuffer);
  536.             break;
  537.         case IDIGNORE:
  538.         default:
  539.             break;
  540.         }
  541.     } while (id == IDRETRY);
  542.  
  543.     _fInAssert = fFalse;
  544. }
  545.  
  546.  
  547. /*  T R A C E */
  548. /*----------------------------------------------------------------------------
  549.     %%Function: Trace
  550.  
  551. ----------------------------------------------------------------------------*/
  552. VOID Trace(PCSTR pcszFormat, ...)
  553. {
  554.     CHAR sz[1024]; // a really large buffer
  555.     wvsprintf(sz, pcszFormat, (PSTR)(&pcszFormat + 1));
  556.  
  557.     Log(LOG_NORMAL, sz);
  558. }
  559.  
  560.  
  561. /*  L O G */
  562. /*-------------------------------------------------------------------------
  563.     %%Function: Log
  564.  
  565. -------------------------------------------------------------------------*/
  566. VOID Log(DWORD grf, LPSTR lpsz)
  567. {
  568.     if (((grf & gPref.grfLog) == 0) || (ghwndMsg == hwndNil))
  569.     {
  570.         return;
  571.     }
  572.  
  573.     // write the string to the Message window
  574.     SendMessage(ghwndMsg, LB_ADDSTRING, 0, (LPARAM) lpsz);
  575.     PostMessage(ghwndMsg, WM_VSCROLL, SB_BOTTOM, 0);
  576. }
  577.  
  578.   
  579. /* C L E A R  L O G */
  580. /*----------------------------------------------------------------------------
  581.     %%Function: ClearLog
  582.  
  583.     Clear the log screen
  584.  
  585. ----------------------------------------------------------------------------*/
  586. VOID ClearLog(void)
  587. {
  588.     SendMessage(ghwndMsg, LB_RESETCONTENT, 0, 0);
  589. }
  590.  
  591. /* L O G  T E S T  S T A R T */
  592. /*----------------------------------------------------------------------------
  593.     %%Function: LogTestStart
  594.  
  595.     Start a test by clearing the log and displaying the string.
  596.  
  597. ----------------------------------------------------------------------------*/
  598. VOID LogTestStart(LPSTR sz)
  599. {
  600.     Log1(LOG_ALWAYS, "==> Running Test %s", sz);
  601. }
  602.  
  603.  
  604. /*  L O G  T E S T  S T O P */
  605. /*----------------------------------------------------------------------------
  606.     %%Function: LogTestStop
  607.  
  608. ----------------------------------------------------------------------------*/
  609. VOID LogTestStop(LPSTR sz)
  610. {
  611.     Log1(LOG_ALWAYS, "==> Test %s Complete", sz);
  612. }
  613.  
  614.  
  615. /*  L O G  R E S U L T */
  616. /*----------------------------------------------------------------------------
  617.     %%Function: LogResult
  618.  
  619. ----------------------------------------------------------------------------*/
  620. VOID LogResult(LPSTR sz, DWORD dwTest, DWORD dwResult)
  621. {
  622.     Log3(LOG_ALWAYS, "%s Test %d Result=%s", sz, dwTest, GetConferrString(dwResult));
  623. }
  624.  
  625.  
  626. static char _szFilter[] = "All Files\0*.*\0Text Files (*.txt)\0*.TXT\0";
  627.  
  628.  
  629.  
  630. /*  F  G E T  F I L E  N A M E */
  631. /*----------------------------------------------------------------------------
  632.     %%Function: FGetFileName
  633.  
  634. ----------------------------------------------------------------------------*/
  635. BOOL FGetFileName(LPSTR szFileName)
  636. {
  637.     OPENFILENAME ofn;
  638.  
  639.     SetEmptySz(szFileName);
  640.     ClearStruct(&ofn);
  641.  
  642.     ofn.lStructSize   = sizeof(OPENFILENAME);
  643.     ofn.hwndOwner     = ghwndMain;
  644.     ofn.hInstance     = (HANDLE) ghInst;
  645.     ofn.lpstrFilter   = _szFilter;
  646.     ofn.nFilterIndex  = 1L;
  647.     ofn.lpstrFile     = (LPSTR) szFileName;
  648.     ofn.nMaxFile      = MAX_PATH; // really sizeof(szFileName)
  649.     ofn.lpstrTitle    = "Pick a file to send";
  650.     ofn.lpstrInitialDir = NULL;
  651.     ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_EXPLORER;
  652.  
  653.     if (!GetOpenFileName(&ofn))
  654.         return fFalse;
  655.  
  656.     return fTrue;
  657. }
  658.  
  659.  
  660.  
  661. /*  F  G E T  D I R E C T O R Y */
  662. /*----------------------------------------------------------------------------
  663.     %%Function: FGetDirectory
  664.  
  665. ----------------------------------------------------------------------------*/
  666. BOOL FGetDirectory(LPSTR szDir)
  667. {
  668.     BOOL  fRet;
  669.     CHAR  szPath[MAX_PATH];
  670.     LPITEMIDLIST pidl;
  671.     LPITEMIDLIST pidlRoot;
  672.     LPMALLOC lpMalloc;
  673.  
  674.     BROWSEINFO bi = {
  675.         ghwndMain,
  676.         NULL,
  677.         szPath,
  678.         "Select a Directory",
  679.         BIF_RETURNONLYFSDIRS,
  680.         NULL, 0L, 0    };
  681.  
  682.     if (0 != SHGetSpecialFolderLocation(HWND_DESKTOP, CSIDL_DRIVES, &pidlRoot))
  683.         return fFalse;
  684.     if (NULL == pidlRoot)
  685.         return fFalse;
  686.  
  687.     bi.pidlRoot = pidlRoot;
  688.     pidl = SHBrowseForFolder(&bi);
  689.  
  690.     if (NULL != pidl)
  691.         fRet = SHGetPathFromIDList(pidl, szDir);
  692.     else
  693.         fRet = fFalse;
  694.  
  695.     // Get the shell's allocator to free PIDLs
  696.     if (!SHGetMalloc(&lpMalloc) && (NULL != lpMalloc))
  697.     {
  698.         if (NULL != pidlRoot)
  699.         {
  700.             lpMalloc->lpVtbl->Free(lpMalloc, pidlRoot);
  701. //            lpMalloc->Free(pidlRoot);
  702.         }
  703.  
  704.         if (NULL != pidl)
  705.         {
  706.             lpMalloc->lpVtbl->Free(lpMalloc, pidl);
  707. //            lpMalloc->Free(pidl);
  708.         }
  709.  
  710.         lpMalloc->lpVtbl->Release(lpMalloc);
  711.     }
  712.  
  713.     return fRet;
  714. }
  715.  
  716.  
  717.  
  718. /*  G E T  R A D I O  B U T T O N */
  719. /*----------------------------------------------------------------------------
  720.     %%Function: GetRadioButton
  721.  
  722. ----------------------------------------------------------------------------*/
  723. int GetRadioButton(HWND hdlg, int idrFirst, int idrLast)
  724. {
  725.     int id;
  726.  
  727.     for (id = idrFirst; id <= idrLast; id++)
  728.     {
  729.         if (IsDlgButtonChecked(hdlg, id))
  730.             return id;
  731.     }
  732.     return idrFirst;
  733. }
  734.  
  735.  
  736. /*  G U I D  T O  S Z */
  737. /*----------------------------------------------------------------------------
  738.     %%Function: GuidToSz
  739.  
  740.     Convert the guid to a hex string.
  741.     Assumes lpchDest has space for at least sizeof(GUID)*2+1 chars.
  742.  
  743.     Note the difference between this and UuidToString (or StringFromGUID2)
  744. ----------------------------------------------------------------------------*/
  745. VOID GuidToSz(GUID * pguid, LPSTR lpchDest)
  746. {
  747.     int i;
  748.  
  749.     ASSERT(NULL != pguid);
  750.     ASSERT(NULL != lpchDest);
  751.  
  752. lstrcpy(lpchDest, "--------------------------------");
  753.  
  754.     wsprintf(lpchDest, "%08X%04X%04X", pguid->Data1, pguid->Data2, pguid->Data3);
  755.     lpchDest += 8+4+4;
  756.     for (i = 0; i < 8; i++)
  757.     {
  758.         wsprintf(lpchDest, "%02X", pguid->Data4[i]);
  759.         lpchDest += 2;
  760.     }
  761. }
  762.  
  763.  
  764. /*  S Z  T O  G U I D */
  765. /*----------------------------------------------------------------------------
  766.     %%Function: SzToGuid
  767.  
  768. ----------------------------------------------------------------------------*/
  769. VOID SzToGuid(LPSTR lpchSrc, GUID * pguid)
  770. {
  771.     if (FEmptySz(lpchSrc) || (CchSz(lpchSrc) < sizeof(GUID)*2))
  772.     {
  773.         ClearStruct(pguid);
  774.         return;
  775.     }
  776.  
  777. ClearStruct(pguid);
  778.  
  779.     lpchSrc = HexToBin(lpchSrc, &pguid->Data1, sizeof(pguid->Data1));
  780.     lpchSrc = HexToBin(lpchSrc, &pguid->Data2, sizeof(pguid->Data2));
  781.     lpchSrc = HexToBin(lpchSrc, &pguid->Data3, sizeof(pguid->Data3));
  782.     HexToData(lpchSrc, pguid->Data4, sizeof(pguid->Data4));
  783. }
  784.     
  785.  
  786.  
  787.  
  788.  
  789.