home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pc3270sa.zip / ddxfer / ddxfer.c < prev    next >
Text File  |  2002-02-28  |  28KB  |  713 lines

  1. /******************************************************************************
  2. *                                                                             *
  3. * Module Name      : ddxfer.c                                                 *
  4. *                                                                             *
  5. * Descriptive name : Drag-and-Drop File Transfer                              *
  6. *                                                                             *
  7. * Author:  IBM                                                                *
  8. * Date Written:  1996                                                         *
  9. * For use with IBM Personal Communications/3270 for Windows 95                *
  10. *                                                                             *
  11. * Notes:                                                                      *
  12. *        This sample uses the Windows Drag and Drop interface. It displays    *
  13. *        the name of the files in a list box, that are dragged from           *
  14. *        FileManager on this app.                                             *
  15. *                                                                             *
  16. * Compiler: Microsoft Visual C++ version 4.00                                 *
  17. *                                                                             *
  18. * Required                                                                    *
  19. *  header : ddxfer.h hapi_c.h hapi_c32.h                                      *
  20. *  lib    : pcscal32.lib                                                      *
  21. *                                                                             *
  22. ******************************************************************************/
  23. /*----------------------------------------------------------------------------*
  24. | Common header files                                                         |
  25. *----------------------------------------------------------------------------*/
  26. #include <windows.h>    // Windows definitions
  27. #include <windowsx.h>   // Windows Macro APIs, window message crackers
  28. #include <shellapi.h>   // Contains Drag/Drop APIs
  29. #include <string.h>     // String
  30.  
  31. /*----------------------------------------------------------------------------*
  32. | Local header files                                                          |
  33. *----------------------------------------------------------------------------*/
  34. #include "ddxfer.h"
  35. #include "hapi_c.h"
  36.  
  37. /*----------------------------------------------------------------------------*
  38. | Local variables                                                             |
  39. *----------------------------------------------------------------------------*/
  40. HANDLE   ghInst;
  41. HWND     ghListBox;
  42. HWND     ghMainWnd;
  43. POINT    gpointDrop = {0,0};  // Point where the files were dropped
  44. WORD     gwFilesDropped = 0;  // Total number of files dropped
  45. BOOL     fAscii = TRUE;
  46. BOOL     fCrlf  = TRUE;
  47. BOOL     fTopmost = TRUE;
  48. BOOL     fTerm = FALSE;
  49. HANDLE   hHllBuffer;
  50. char     szOptions[128];
  51. char     szVMDisk[3];
  52. char     szSessID[2];
  53. /*-----------------------------------------------------------------------------*
  54. |                                                                              |
  55. |   FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)                              |
  56. |                                                                              |
  57. |   PURPOSE:                                                                   |
  58. |                                                                              |
  59. |   This function creates the main window and the list box, registers the      |
  60. |   main window to accept Drag/Drop messages, and goes in the message loop.    |
  61. |                                                                              |
  62. *-----------------------------------------------------------------------------*/
  63. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  64. HANDLE   hInstance;
  65. HANDLE   hPrevInstance;
  66. LPSTR    lpszCmdLine;
  67. int      nCmdShow;
  68. {
  69.    MSG         msg;
  70.    WNDCLASS    wc;
  71.    RECT        rectMain;
  72.    LPSTR       lpHllBuffer ;
  73.    char        szBuffer1[BUFFER_LENGTH] ;
  74.    char        szBuffer2[BUFFER_LENGTH] ;
  75.  
  76.    // Allocate buffer
  77.    if (!(hHllBuffer = GlobalAlloc(FGString, (DWORD)HLLAPIBUFFER)))
  78.       return FALSE ;
  79.  
  80.    if (!(lpHllBuffer = GlobalLock(hHllBuffer)))
  81.    {
  82.       GlobalFree(hHllBuffer) ;
  83.       return FALSE ;
  84.    }
  85.  
  86.    if (lstrlen(lpszCmdLine))
  87.       lstrcpy(lpHllBuffer, lpszCmdLine) ;
  88.  
  89.    if (!hPrevInstance)
  90.    {
  91.       LoadString(hInstance, LS_MENU, (LPSTR)szBuffer1, sizeof(szBuffer1));
  92.       LoadString(hInstance, LS_CLASS, (LPSTR)szBuffer2, sizeof(szBuffer2));
  93.       wc.style         = (unsigned int)NULL;
  94.       wc.lpfnWndProc   = MainWndProc;
  95.       wc.cbClsExtra    = 0;
  96.       wc.cbWndExtra    = 0;
  97.       wc.hInstance     = hInstance;
  98.       wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(DDXFER));
  99.       wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  100.       wc.hbrBackground = GetStockObject (WHITE_BRUSH);
  101.       wc.lpszMenuName  = (LPSTR)szBuffer1;
  102.       wc.lpszClassName = (LPSTR)szBuffer2;
  103.  
  104.       if (!RegisterClass (&wc))
  105.          return FALSE;
  106.    }
  107.  
  108.    LoadString(hInstance, LS_TITLE, (LPSTR)szBuffer1, sizeof(szBuffer1));
  109.    ghMainWnd = CreateWindow((LPSTR)szBuffer2,
  110.                             (LPSTR)szBuffer1,
  111.                             WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
  112.                             WS_MINIMIZEBOX,
  113.                             CW_USEDEFAULT,
  114.                             CW_USEDEFAULT,
  115.                             MAIN_WIDTH,
  116.                             MAIN_HEIGHT,
  117.                             NULL,
  118.                             NULL,
  119.                             hInstance,
  120.                             NULL);
  121.  
  122.    if (!ghMainWnd)
  123.        return FALSE;
  124.  
  125.    GetClientRect(ghMainWnd, &rectMain);
  126.  
  127.    LoadString(hInstance, LS_LISTBOX, (LPSTR)szBuffer1, sizeof(szBuffer1));
  128.    ghListBox = CreateWindow((LPSTR)szBuffer1,
  129.                             NULL,
  130.                             WS_CHILD | WS_VSCROLL | WS_HSCROLL
  131.                             | LBS_NOINTEGRALHEIGHT | WS_VISIBLE
  132.                             | LBS_NOTIFY | LBS_SORT,
  133.                             0,
  134.                             0,
  135.                             rectMain.right - rectMain.left,
  136.                             rectMain.bottom - rectMain.top,
  137.                             ghMainWnd,
  138.                             (HMENU)IDD_LIST,
  139.                             hInstance,
  140.                             NULL);
  141.  
  142.    if (!ghListBox)
  143.       return FALSE;
  144.  
  145.    // Register the the main window for Drag/Drop messages.
  146.    DragAcceptFiles(ghMainWnd, TRUE);
  147.  
  148.    ShowWindow(ghMainWnd, nCmdShow);
  149.    UpdateWindow(ghMainWnd);
  150.  
  151.    ghInst = hInstance;
  152.  
  153.    while (GetMessage (&msg, NULL, (unsigned int)NULL, (unsigned int)NULL))
  154.    {
  155.       TranslateMessage (&msg);
  156.       DispatchMessage (&msg);
  157.    }
  158.    return msg.wParam;
  159. }
  160.  
  161.  
  162. /*-----------------------------------------------------------------------------*
  163. |                                                                              |
  164. |   FUNCTION: MainWndProc()                                                    |
  165. |                                                                              |
  166. |   PURPOSE:                                                                   |
  167. |                                                                              |
  168. |   This function handles messages belonging to the main window.               |
  169. |   It also handles and processes Drag/Drop messages.                          |
  170. |                                                                              |
  171. *-----------------------------------------------------------------------------*/
  172. LONG FAR PASCAL MainWndProc (hWnd, iMessage, wParam, lParam)
  173. HWND     hWnd;
  174. UINT     iMessage;
  175. WPARAM   wParam;
  176. LPARAM   lParam;
  177. {
  178.    FARPROC  lpDialogProc;
  179.    HANDLE   hFilesInfo;
  180.    WORD     wIndex;
  181.    HANDLE   hMenu;
  182.    int      iPlace;
  183.    int      iCount ;
  184.    char     szFileName[FILENAME_LENGTH];
  185.    char     szHostFile[FILENAME_LENGTH];
  186.    char     szFormat[BUFFER_LENGTH];
  187.    char     szList[BUFFER_LENGTH];
  188.    char     szSpace[2] ;
  189.    LPSTR    lpHllBuffer;
  190.    LPSTR    lpToken ;
  191.  
  192.    switch (iMessage)
  193.    {
  194.       case WM_DROPFILES:
  195.          hFilesInfo = (HANDLE) wParam;
  196.  
  197.          // Retrieve the window coordinates of the mouse
  198.          // pointer when the drop was made
  199.          DragQueryPoint ((HANDLE) wParam, (LPPOINT) &gpointDrop);
  200.  
  201.          // Get the total number of files dropped
  202.          gwFilesDropped = DragQueryFile (hFilesInfo,
  203.                                         (UINT)-1,
  204.                                         NULL,
  205.                                         0);
  206.  
  207.          // Reset terminate flag
  208.          fTerm = FALSE ;
  209.  
  210.          // Retrieve each file name and add to the list box
  211.          for (wIndex=0 ; wIndex < gwFilesDropped ; wIndex++)
  212.          {
  213.             DragQueryFile(hFilesInfo,
  214.                           wIndex,
  215.                           (LPSTR)szFileName,
  216.                           FILENAME_LENGTH);
  217.  
  218.             GenerateHostFile((LPSTR)szFileName, (LPSTR)szHostFile);
  219.             SendParmProc(hWnd, (LPSTR)szFileName, (LPSTR)szHostFile, ID_SEND);
  220.  
  221.             if (!(lpHllBuffer = GlobalLock(hHllBuffer)))
  222.                break;
  223.             AnsiLower(lpHllBuffer);
  224.  
  225.             lpToken = _fstrchr((LPSTR)szHostFile, ':') ;
  226.             LoadString(ghInst, LS_LIST, (LPSTR)szFormat, sizeof(szFormat)) ;
  227.             wsprintf((LPSTR)szList, (LPSTR)szFormat, (LPSTR)szFileName,
  228.                      (LPSTR)(lpToken + 1), szSessID[0]) ;
  229.             AnsiLower((LPSTR)szList) ;
  230.             SendMessage(ghListBox, LB_SETHORIZONTALEXTENT, (WPARAM)500, 0L);
  231.             SendMessage(ghListBox,
  232.                         LB_ADDSTRING,
  233.                         0,
  234.                         (LONG)(LPSTR)szList);
  235.  
  236.             GlobalUnlock(hHllBuffer);
  237.  
  238.             if (fTerm)
  239.                break;
  240.          }
  241.          DragFinish(hFilesInfo);
  242.          break;
  243.  
  244.       case WM_COMMAND:
  245.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  246.          {
  247.             case IDD_LIST:
  248.                if (GET_WM_COMMAND_CMD(wParam,lParam) == LBN_DBLCLK)
  249.                {
  250.                   if (!(lpHllBuffer = GlobalLock(hHllBuffer)))
  251.                      break;
  252.  
  253.                   // Get one line
  254.                   SendDlgItemMessage(hWnd, IDD_LIST, LB_GETTEXT, 0,
  255.                                      (LONG)(LPSTR)szList) ;
  256.                   szSpace[0] = ' ' ;
  257.                   szSpace[1] = (char)NULL ;
  258.  
  259.                   // DOS file name
  260.                   lpToken = _fstrtok((LPSTR)szList, (LPSTR)szSpace) ;
  261.                   lstrcpy(lpHllBuffer, lpToken) ;
  262.                   lstrcat(lpHllBuffer, (LPSTR)szSpace) ;
  263.                   iPlace = lstrlen(lpHllBuffer) ;  // Store place of session ID
  264.                   // Add dummy spaces
  265.                   lstrcat(lpHllBuffer, (LPSTR)szSpace) ;
  266.                   lstrcat(lpHllBuffer, (LPSTR)szSpace) ;
  267.  
  268.                   // "-->" (skipped)
  269.                   lpToken = _fstrtok(NULL, (LPSTR)szSpace) ;
  270.  
  271.                   for (iCount = 0 ; iCount < 3 ; iCount++)
  272.                   {
  273.                      // Host file name/type/mode
  274.                      lpToken = _fstrtok(NULL, (LPSTR)szSpace) ;
  275.                      lstrcat(lpHllBuffer, lpToken) ;
  276.                      lstrcat(lpHllBuffer, (LPSTR)szSpace) ;
  277.                   }
  278.  
  279.                   // "(Session"
  280.                   lpToken = _fstrtok(NULL, (LPSTR)szSpace) ;
  281.                   // Session ID
  282.                   lpToken = _fstrtok(NULL, (LPSTR)szSpace) ;
  283.  
  284.                   *(lpHllBuffer + iPlace) = *lpToken ;
  285.                   *(lpHllBuffer + iPlace + 1) = ':' ;
  286.  
  287.                   lpToken = (lpHllBuffer + lstrlen(lpHllBuffer));
  288.                   *(lpToken++) = ' ';
  289.                   GetOption(lpToken);
  290.  
  291.                   GlobalUnlock(hHllBuffer);
  292.                   SendArgProc(hWnd) ;
  293.                }
  294.                break;
  295.  
  296.             case IDM_ABOUT:
  297.                lpDialogProc = MakeProcInstance (About, ghInst);
  298.                DialogBox (ghInst,
  299.                           MAKEINTRESOURCE(ABOUTBOX),
  300.                           hWnd,
  301.                           lpDialogProc);
  302.                FreeProcInstance (lpDialogProc);
  303.                break;
  304.  
  305.             case IDM_TEXT:
  306.                lpDialogProc = MakeProcInstance(TextDlgProc, ghInst);
  307.                DialogBox(ghInst,
  308.                          MAKEINTRESOURCE(TEXTBOX),
  309.                          hWnd,
  310.                          lpDialogProc);
  311.                FreeProcInstance (lpDialogProc);
  312.                break;
  313.  
  314.             case IDM_TITLE:
  315.                lpDialogProc = MakeProcInstance(TitleDlgProc, ghInst);
  316.                DialogBox(ghInst,
  317.                          MAKEINTRESOURCE(TITLEBOX),
  318.                          hWnd,
  319.                          lpDialogProc);
  320.                FreeProcInstance (lpDialogProc);
  321.                break;
  322.  
  323.             case  IDM_TOP:
  324.                hMenu = GetMenu(hWnd);
  325.                if (fTopmost)
  326.                {
  327.                   fTopmost = FALSE;
  328.                   CheckMenuItem(hMenu, IDM_TOP, MF_UNCHECKED) ;
  329.                }
  330.                else
  331.                {
  332.                   fTopmost = TRUE;
  333.                   CheckMenuItem(hMenu, IDM_TOP, MF_CHECKED) ;
  334.                }
  335.                SetWindowPos(hWnd, (fTopmost ? HWND_TOPMOST : HWND_NOTOPMOST),
  336.                             0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE |
  337.                             SWP_NOMOVE);
  338.                break;
  339.  
  340.             case  IDM_TERM:
  341.                fTerm = TRUE;
  342.                break;
  343.  
  344.             case  IDM_CLEAR :
  345.                SendDlgItemMessage(hWnd, IDD_LIST, LB_RESETCONTENT, 0, 0L);
  346.                break;
  347.  
  348.             default:
  349.                return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  350.          }
  351.          break;
  352.  
  353.       case WM_DESTROY:
  354.          GlobalFree(hHllBuffer) ;
  355.          PostQuitMessage (0);
  356.          break;
  357.  
  358.       case WM_CREATE:
  359.          // Set default VM disk
  360.          szVMDisk[0] = 'A' ;
  361.          szVMDisk[1] = (char)NULL ;
  362.  
  363.          // Set default Session ID
  364.          szSessID[0] = 'A' ;
  365.          szSessID[1] = (char)NULL ;
  366.  
  367.          // Check menu
  368.          hMenu = GetMenu(hWnd) ;
  369.          if (fTopmost)
  370.          {
  371.             CheckMenuItem(hMenu, IDM_TOP, MF_CHECKED) ;
  372.             SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0,
  373.                          SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  374.          }
  375.          else
  376.          {
  377.             CheckMenuItem(hMenu, IDM_TOP, MF_UNCHECKED) ;
  378.             SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
  379.                          SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOMOVE);
  380.          }
  381.  
  382.       default:
  383.          return DefWindowProc (hWnd, iMessage, wParam, lParam);
  384.  
  385.    }
  386.    return 0L;
  387. }
  388.  
  389. /*-----------------------------------------------------------------------------*
  390. |                                                                              |
  391. |   FUNCTION: About()                                                          |
  392. |                                                                              |
  393. |   PURPOSE:                                                                   |
  394. |                                                                              |
  395. *-----------------------------------------------------------------------------*/
  396. BOOL FAR PASCAL About (hDlg, iMessage, wParam, lParam)
  397. HWND     hDlg;
  398. UINT     iMessage;
  399. WPARAM   wParam;
  400. LPARAM   lParam;
  401. {
  402.    switch (iMessage)
  403.    {
  404.       case WM_INITDIALOG:
  405.          return TRUE;
  406.  
  407.       case WM_COMMAND:
  408.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  409.          {
  410.             case IDOK:
  411.             case IDCANCEL:
  412.                EndDialog (hDlg, TRUE);
  413.                return TRUE;
  414.  
  415.             default:
  416.                break;
  417.          }
  418.    }
  419.    return FALSE;
  420. }
  421.  
  422. /*-----------------------------------------------------------------------------*
  423. |                                                                              |
  424. |   FUNCTION: TextDlgProc                                                      |
  425. |                                                                              |
  426. |   PURPOSE:                                                                   |
  427. |                                                                              |
  428. |   This function handles messages belonging to the "Options" dialog box.      |
  429. |   It displays information of options.                                        |
  430. |                                                                              |
  431. *-----------------------------------------------------------------------------*/
  432. BOOL FAR PASCAL TextDlgProc(hDlg, iMessage, wParam, lParam)
  433. HWND     hDlg;
  434. UINT     iMessage;
  435. WPARAM   wParam;
  436. LPARAM   lParam;
  437. {
  438.    switch (iMessage)
  439.    {
  440.       case WM_INITDIALOG:
  441.          CheckDlgButton(hDlg, IDD_ASCII, fAscii);
  442.          CheckDlgButton(hDlg, IDD_CRLF,  fCrlf);
  443.          SetDlgItemText(hDlg, IDD_ADDITIONAL, (LPSTR)szOptions);
  444.          SetDlgItemText(hDlg, IDD_VMDISK,     (LPSTR)szVMDisk);
  445.          SetDlgItemText(hDlg, IDD_SESSID,     (LPSTR)szSessID);
  446.          return TRUE;
  447.  
  448.       case WM_COMMAND:
  449.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  450.          {
  451.             case IDOK:
  452.                fAscii = IsDlgButtonChecked(hDlg, IDD_ASCII);
  453.                fCrlf  = IsDlgButtonChecked(hDlg, IDD_CRLF);
  454.                GetDlgItemText(hDlg, IDD_ADDITIONAL, (LPSTR)szOptions,
  455.                               sizeof(szOptions));
  456.  
  457.                GetDlgItemText(hDlg, IDD_VMDISK, (LPSTR)szVMDisk,
  458.                               sizeof(szVMDisk));
  459.  
  460.                GetDlgItemText(hDlg, IDD_SESSID, (LPSTR)szSessID,
  461.                               sizeof(szSessID));
  462.  
  463.                EndDialog (hDlg, TRUE);
  464.                return TRUE;
  465.  
  466.             case IDCANCEL:
  467.                EndDialog (hDlg, FALSE);
  468.                return TRUE;
  469.  
  470.             default:
  471.                break;
  472.          }
  473.    }
  474.    return FALSE;
  475. }
  476.  
  477. /*-----------------------------------------------------------------------------*
  478. |                                                                              |
  479. |   FUNCTION: TitleDlgProc                                                     |
  480. |                                                                              |
  481. |   PURPOSE:                                                                   |
  482. |                                                                              |
  483. |   This function handles messages belonging to the "Change Title" dialog box. |
  484. |   It displays information of options.                                        |
  485. |                                                                              |
  486. *-----------------------------------------------------------------------------*/
  487. BOOL FAR PASCAL TitleDlgProc(hDlg, iMessage, wParam, lParam)
  488. HWND     hDlg;
  489. UINT     iMessage;
  490. WPARAM   wParam;
  491. LPARAM   lParam;
  492. {
  493.    char  szTitle[TITLE_LEN];
  494.  
  495.    switch (iMessage)
  496.    {
  497.       case WM_INITDIALOG:
  498.          GetWindowText(ghMainWnd, (LPSTR)szTitle, sizeof(szTitle)) ;
  499.          SetDlgItemText(hDlg, IDD_TITLE, (LPSTR)szTitle) ;
  500.          return TRUE;
  501.  
  502.       case WM_COMMAND:
  503.          switch (GET_WM_COMMAND_ID(wParam,lParam))
  504.          {
  505.             case IDOK:
  506.                GetDlgItemText(hDlg, IDD_TITLE, (LPSTR)szTitle,
  507.                               sizeof(szTitle));
  508.                SetWindowText(ghMainWnd, (LPSTR)szTitle);
  509.                EndDialog (hDlg, TRUE);
  510.                return TRUE;
  511.  
  512.             case IDCANCEL:
  513.                EndDialog (hDlg, FALSE);
  514.                return TRUE;
  515.  
  516.             default:
  517.                break;
  518.          }
  519.    }
  520.    return FALSE;
  521. }
  522.  
  523. /*-----------------------------------------------------------------------------*
  524. |                                                                              |
  525. |   FUNCTION: SendArgProc                                                      |
  526. |                                                                              |
  527. |   PURPOSE:                                                                   |
  528. |                                                                              |
  529. |   This function calls hllapi send file function if parameters specified      |
  530. |   in command argument of this exec.                                          |
  531. |                                                                              |
  532. *-----------------------------------------------------------------------------*/
  533. VOID PASCAL SendArgProc(hWnd)
  534. HWND  hWnd ;
  535. {
  536.    int   HllFunc, HllStrLen, HllRetCode;
  537.    LPSTR lpHllBuffer;
  538.  
  539.    /*--------------------------------------------------------------------------*
  540.    |                                                                           |
  541.    |    HLLAPI call                                                            |
  542.    |    Send file (90)                                                         |
  543.    |                                                                           |
  544.    *--------------------------------------------------------------------------*/
  545.    if (!(lpHllBuffer = GlobalLock(hHllBuffer)))
  546.       return;
  547.  
  548.    HllFunc   = 90;
  549.    HllStrLen = lstrlen(lpHllBuffer);
  550.  
  551.    hllapi((LPINT)&HllFunc,
  552.           (LPSTR)lpHllBuffer,
  553.           (LPINT)&HllStrLen,
  554.           (LPINT)&HllRetCode);
  555.  
  556.    GlobalUnlock(hHllBuffer);
  557.    return;
  558. }
  559.  
  560. /*-----------------------------------------------------------------------------*
  561. |                                                                              |
  562. |   FUNCTION: SendParmProc()                                                   |
  563. |                                                                              |
  564. |   PURPOSE:                                                                   |
  565. |                                                                              |
  566. |   This function calls hllapi send file function using parameters from        |
  567. |   options.                                                                   |
  568. |                                                                              |
  569. *-----------------------------------------------------------------------------*/
  570. VOID PASCAL SendParmProc(hWnd, lpszPCFile, lpszHostFile, bSR)
  571. HWND  hWnd;
  572. LPSTR lpszPCFile;
  573. LPSTR lpszHostFile;
  574. BOOL  bSR;
  575. {
  576.    int      HllFunc, HllStrLen, HllRetCode;
  577.    LPSTR    lpHllBuffer;
  578.    LPSTR    lpToken;
  579.  
  580.    /*--------------------------------------------------------------------------*
  581.    |                                                                           |
  582.    |    HLLAPI call                                                            |
  583.    |    Send file (90) / Receive file (91)                                     |
  584.    |                                                                           |
  585.    *--------------------------------------------------------------------------*/
  586.    if (!(lpHllBuffer = GlobalLock(hHllBuffer)))
  587.       return;
  588.  
  589.    strncpy(lpHllBuffer, lpszPCFile, lstrlen(lpszPCFile) + 1);
  590.    lpToken = lpHllBuffer + lstrlen(lpszPCFile);
  591.    *(lpToken++) = ' ';
  592.    strncpy(lpToken, lpszHostFile, lstrlen(lpszHostFile) + 1);
  593.    lpToken += lstrlen(lpszHostFile);
  594.    *(lpToken++) = ' ';
  595.  
  596.    GetOption(lpToken);
  597.  
  598.    HllFunc   = 90 + bSR;
  599.    HllStrLen = lstrlen(lpHllBuffer);
  600.  
  601.    hllapi((LPINT)&HllFunc,
  602.           (LPSTR)lpHllBuffer,
  603.           (LPINT)&HllStrLen,
  604.           (LPINT)&HllRetCode);
  605.  
  606.    GlobalUnlock(hHllBuffer);
  607.    return;
  608. }
  609.  
  610. /*-----------------------------------------------------------------------------*
  611. |                                                                              |
  612. |   FUNCTION: GenerateHostFile()                                               |
  613. |                                                                              |
  614. |   PURPOSE:                                                                   |
  615. |                                                                              |
  616. |   This function generates host file name from pc file name.                  |
  617. |                                                                              |
  618. *-----------------------------------------------------------------------------*/
  619. BOOL PASCAL GenerateHostFile(lpszPCFile, lpszHostFile)
  620. LPSTR lpszPCFile ;
  621. LPSTR lpszHostFile ;
  622. {
  623.    LPSTR lpToken ;
  624.    WORD  wLength ;
  625.    char  szPCFile[FILENAME_LENGTH] ;
  626.    char  szBuffer[BUFFER_LENGTH] ;
  627.  
  628.    if (lpToken = _fstrrchr(lpszPCFile, '\\'))
  629.    {
  630.       lstrcpy((LPSTR)szPCFile, lpToken + 1) ;
  631.    }
  632.  
  633.    if (lpToken = _fstrchr((LPSTR)szPCFile, '.'))
  634.    {
  635.       *lpToken = (char)NULL ;
  636.       wLength = lstrlen((LPSTR)szPCFile) ;
  637.  
  638.       // Get host file name (with session ID)
  639.       szBuffer[0] = ':';
  640.       szBuffer[1] = (char)NULL;
  641.       lstrcpy(lpszHostFile, (LPSTR)szSessID);
  642.       lstrcat(lpszHostFile, (LPSTR)szBuffer) ;
  643.       lstrcat(lpszHostFile, (LPSTR)szPCFile);
  644.       szBuffer[0] = ' ';
  645.       lstrcat(lpszHostFile, (LPSTR)szBuffer);
  646.       *(lpToken++) = '.';
  647.  
  648.       // Get host file type
  649.       lstrcat(lpszHostFile, lpToken);
  650.       lstrcat(lpszHostFile, (LPSTR)" ");
  651.  
  652.       // Add file mode
  653.       lstrcat(lpszHostFile, (LPSTR)szVMDisk);
  654.    }
  655.    else
  656.    {
  657.       // File name only. No extension
  658.       lstrcpy(lpszHostFile, lpszPCFile);
  659.  
  660.       // Add default file type
  661.       LoadString(ghInst, LS_TYPE, (LPSTR)szBuffer, sizeof(szBuffer));
  662.       lstrcat(lpszHostFile, (LPSTR)szBuffer);
  663.  
  664.       // Add file mode
  665.       lstrcat(lpszHostFile, (LPSTR)szVMDisk);
  666.    }
  667.  
  668.    return TRUE;
  669. }
  670.  
  671. /*-----------------------------------------------------------------------------*
  672. |                                                                              |
  673. |   FUNCTION: GetOptions()                                                     |
  674. |                                                                              |
  675. |   PURPOSE:                                                                   |
  676. |                                                                              |
  677. |   This function generates host file name from pc file name.                  |
  678. |                                                                              |
  679. *-----------------------------------------------------------------------------*/
  680. VOID PASCAL GetOption(lpToken)
  681. LPSTR lpToken;
  682. {
  683.    char     szMessage[64];
  684.  
  685.    *(lpToken++) = '(';
  686.    *(lpToken++) = ' ';
  687.  
  688.    if (fAscii)
  689.    {
  690.       LoadString(ghInst, LS_ASCII, (LPSTR)szMessage, sizeof(szMessage));
  691.       strncpy(lpToken, (LPSTR)szMessage, 6);
  692.       lpToken += 5;
  693.       *(lpToken++) = ' ';
  694.       *lpToken = (char)NULL;
  695.    }
  696.  
  697.    if (fCrlf)
  698.    {
  699.       LoadString(ghInst, LS_CRLF, (LPSTR)szMessage, sizeof(szMessage));
  700.       strncpy(lpToken, (LPSTR)szMessage, 5);
  701.       lpToken += 4;
  702.       *(lpToken++) = ' ';
  703.       *lpToken = (char)NULL;
  704.    }
  705.  
  706.    if (lstrlen(szOptions))
  707.    {
  708.       strncpy(lpToken, (LPSTR)szOptions, lstrlen((LPSTR)szOptions) + 1);
  709.       lpToken += (lstrlen((LPSTR)szOptions) + 1);
  710.       *lpToken = (char)NULL;
  711.    }
  712. }
  713.