Small example on File Mapping encapsulation.
Save the source as mapfile.bas.
Regards,
RValois.
Save the source as mapfile.bas.
Code:
#Compiler PBWin 9 #Compile Exe #Dim All #Include "win32api.inc" '****************************************************************************** Class CMapFile '****************************************************************************** Instance pData As Dword Instance hFileMap As Dword Instance hFile As Dword '**************************************************************************** Interface IMapFile '**************************************************************************** Inherit IUnknown '************************************************************************** Method Open(ByRef FileName As String) As Long '************************************************************************** If IsFile(FileName) Then hFile = CreateFile (ByVal StrPtr(FileName), %GENERIC_READ, %FILE_SHARE_READ, ByVal %NULL, %OPEN_EXISTING, %FILE_ATTRIBUTE_NORMAL, ByVal %NULL) If hFile Then hFileMap = CreateFileMapping (hFile, ByVal %NULL, %PAGE_READONLY, ByVal %NULL, ByVal %NULL, ByVal %NULL) If hFileMap Then pData = MapViewOfFile (hFileMap, %FILE_MAP_READ, ByVal %NULL, ByVal %NULL, ByVal %NULL) If pData Then Method = pData Exit Method End If End If End If End If me.Close Method = %False End Method '************************************************************************** Method Close '************************************************************************** If pData Then UnmapViewOfFile pData pData = 0 End If If hFileMap Then CloseHandle hFileMap hFileMap = 0 End If If hFile Then CloseHandle hFile hFile = 0 End If End Method End Interface '****************************************************************************** End Class '****************************************************************************** 'Teste Code '****************************************************************************** Function PBMain As Long '****************************************************************************** Local pMem As Asciiz Ptr Dim MapFile As IMapFile Let MapFile = Class "CMapFile" pMem = MapFile.Open("mapfile.log") If pMem Then MsgBox "MapFile Class Test" + $CrLf + $CrLf + $CrLf + @pMem MapFile.Close End If End Function '****************************************************************************** 'END Program '******************************************************************************
RValois.