You asked: CreatMapFile & Pascal

From the logfile, a Polish person looking for CreateFileMapping, most likely using Delphi. The WIN32 API function is generally used in conjunction with ‘MapViewOfFile’. You’d generally use memory mapped files when you run into a TStringList limitation. At this stage, you’d probably cursing the Delphi implementors.

Your first step is to create the filemap like this:

// fileMapHandle = THandle, filehandler = integer. Choose your mapping
// protection appropriately (in this case I used page_readonly
fileMapHandle := CreateFileMapping(filehandler, nil, 
  page_readonly, 0, 0, nil)

Verify if a handle was returned (you probably also want to use GetLastError). Your next step is to actually map the file to an address using MapViewOfFile. It is probably handy to learn about PChars at this stage (note this is an example that comes from Fandro: in this case the ‘magic search’ happens in a function called ‘SetData’):

  // size == integer.
  if fileMapHandle <> 0 then
    SetData(MapViewOfFile(fileMapHandle,
      file_map_read,0,0,0),size)

When done processing, don’t forget to close (any) open handles:

  CloseHandle(fileMapHandle);

And that’s it!

This entry was posted in Programming, You-Asked. Bookmark the permalink.

One Response to You asked: CreatMapFile & Pascal

  1. Saskboy says:

    Thanks Arthur for the kudos, and congrats to you too, for making it to the Canadian Blog Awards round 2.

Comments are closed.