home *** CD-ROM | disk | FTP | other *** search
/ WarCraft 2000 - Nuclear Epidemic / W2000.nrg / SOURCE.War2000 / Resfile.cpp < prev    next >
C/C++ Source or Header  |  1998-03-23  |  1KB  |  56 lines

  1. /*      Work with the resource files
  2.  *   
  3.  *  You must use this module for accesss to files this 
  4.  * routine allows you to read files from disk or from 
  5.  * the resource file, you even will not recognise where
  6.  * the given file is.
  7.  */
  8. #include <afx.h>
  9. //#include <windows.h>
  10. #include <stdlib.h>
  11. typedef HANDLE ResFile;
  12. //Opening the resource file
  13. ResFile RReset(LPCSTR lpFileName)
  14. {
  15.     SetLastError(0);
  16.     return CreateFile(lpFileName,GENERIC_READ,FILE_SHARE_READ,NULL,
  17.                                  OPEN_EXISTING,0/*FILE_ATTRIBUTE_NORMAL*/,NULL);
  18. }
  19. //Rewriting file
  20. ResFile RRewrite(LPCSTR lpFileName)
  21. {
  22.     return CreateFile(lpFileName,GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,
  23.                                  CREATE_ALWAYS,0,NULL);
  24. }
  25. //Getting size of the resource file
  26. DWORD RFileSize(HANDLE hFile)
  27. {
  28.     return GetFileSize(hFile,NULL);
  29. }
  30. // Setting file position 
  31. DWORD RSeek(ResFile hFile,int pos)
  32. {
  33.     return SetFilePointer(hFile,pos,NULL,FILE_BEGIN);
  34. }
  35. //Reading the file
  36. DWORD RBlockRead(ResFile hFile,LPVOID lpBuffer,DWORD BytesToRead)
  37. {
  38.     DWORD readBytes;
  39.     ReadFile(hFile,lpBuffer,BytesToRead,&readBytes,NULL);
  40.     return readBytes;
  41. }
  42. //Writing the file
  43. DWORD RBlockWrite(ResFile hFile,LPVOID lpBuffer,DWORD BytesToWrite)
  44. {
  45.     DWORD writeBytes;
  46.     WriteFile(hFile,lpBuffer,BytesToWrite,&writeBytes,NULL);
  47.     return writeBytes;
  48. }
  49. DWORD IOresult(void)
  50. {
  51.     return GetLastError();
  52. }
  53. void RClose(ResFile hFile)
  54. {
  55.     CloseHandle(hFile);
  56. }