Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2005 Aug : Why Lock Map File

www.cryer.info
Managed Newsgroup Archive

Why Lock Map File

Subject:Why Lock Map File
Posted by:"Daniel" (dan593..@ms3.hinet.net)
Date:Wed, 31 Aug 2005 11:04:20 +0800

I Create a Map File named 'Shared_Memory' with CreateFileMapping( ).

Then use the following code try to lock it..


procedure LockMap(var hMutex:THandle);
begin
    hMutex := CreateMutex(nil, false, 'Shared_Memory')

      if hMutex = 0 then
      begin
        ShowMessage('Failed');
        Result := false;
      end
      else
      begin
        if WaitForSingleObject(hMutex,REQUEST_TIMEOUT) =     WAIT_FAILED
then
       begin
          // timeout
          ShowMessage('Can't lock memory mapped file');
          Result := false;
        end
      end;
end;

but the hMuteX aloways retun 0,  lock failed.


Why lock failed? What exactlly Lock Map File does?  Does it lock the Map
File and not allow other applications to read/write the Map File?


Thanks,

Daniel

Glossary

Replies:

www.cryer.info
Managed Newsgroup Archive