home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap18 / cosmo1.0 / fileio.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  2KB  |  100 lines

  1. /*
  2.  * FILEIO.C
  3.  *
  4.  * Functions for low-level reading and writing of .COS files.
  5.  *
  6.  * Functions:
  7.  *  FCosFileRead, FCosFileWrite
  8.  *
  9.  * Copyright(c) Microsoft Corp. 1992-1994 All Rights Reserved
  10.  * Win32 version, January 1994
  11.  */
  12.  
  13. #include <windows.h>
  14. #include "cosmo.h"
  15.  
  16.  
  17. /*
  18.  * FCosFileRead
  19.  *
  20.  * Purpose:
  21.  *  Reads a Cos file into the POLYLINE structure pointed to by lppl.
  22.  *  Clears pGlob->fDirty on success.
  23.  *
  24.  * Parameters:
  25.  *  pGlob           LPGLOBALS to the global variable block.
  26.  *  pszFile         LPSTR of the filename to read.
  27.  *  lppl            LPPOLYLINE to the structure to fill.
  28.  *
  29.  * Return Value:
  30.  *  BOOL            TRUE if the file was successfully read,
  31.  *                  FALSE otherwise.
  32.  */
  33.  
  34. BOOL WINAPI FCosFileRead(LPGLOBALS pGlob, LPSTR pszFile, LPPOLYLINE lppl)
  35.     {
  36.     int         hFile;
  37.     OFSTRUCT    of;
  38.     UINT        cb;
  39.  
  40.     hFile=OpenFile(pszFile, &of, OF_READ);
  41.  
  42.     if (-1==hFile)
  43.         return FALSE;
  44.  
  45.     cb=_lread(hFile, (LPSTR)lppl, CBPOLYLINE);
  46.     _lclose(hFile);
  47.  
  48.     if (CBPOLYLINE==cb && VERSIONMAJOR==lppl->wVerMaj
  49.         && VERSIONMINOR==lppl->wVerMin)
  50.         {
  51.         pGlob->fDirty=FALSE;
  52.         return TRUE;
  53.         }
  54.  
  55.     return FALSE;
  56.     }
  57.  
  58.  
  59.  
  60.  
  61. /*
  62.  * FCosFileWrite
  63.  *
  64.  * Purpose:
  65.  *  Writes a Cos file into the POLYLINE structure pointed to by lppl.
  66.  *  Clears pGlob->fDirty.
  67.  *
  68.  * Parameters:
  69.  *  pGlob           LPGLOBALS to the global variable block.
  70.  *  pszFile         LPSTR of the filename to read.
  71.  *  lppl            LPPOLYLINE to the structure to write from.
  72.  *
  73.  * Return Value:
  74.  *  BOOL            TRUE if the file was successfully written,
  75.  *                  FALSE otherwise.
  76.  */
  77.  
  78. BOOL WINAPI FCosFileWrite(LPGLOBALS pGlob, LPSTR pszFile, LPPOLYLINE lppl)
  79.     {
  80.     int         hFile;
  81.     OFSTRUCT    of;
  82.     UINT        cb;
  83.  
  84.     hFile=OpenFile(pszFile, &of, OF_CREATE | OF_WRITE);
  85.  
  86.     if (-1==hFile)
  87.         return FALSE;
  88.  
  89.     cb=_lwrite(hFile, (LPSTR)lppl, CBPOLYLINE);
  90.     _lclose(hFile);
  91.  
  92.     if (CBPOLYLINE==cb)
  93.         {
  94.         pGlob->fDirty=FALSE;
  95.         return TRUE;
  96.         }
  97.  
  98.     return FALSE;
  99.     }
  100.