sit and go strategy

c++ / delphi package - dll injection and api hooking
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

What kind of race condition do you mean exactly? The creation/opening of the file mapping is thread safe. But accessing the content of the file mapping should be synchronized (like every kind of global buffer).
zcecil
Posts: 22
Joined: Thu Sep 09, 2004 8:16 am

Post by zcecil »

Sorry, but I can't figure out how to use Create/OpenGlobalFileMapping in BCB.

I can't make MapViewOfFile take DWORD as File Handle, so I try this:

Code: Select all

    DWORD hFile = OpenGlobalFileMapping("TEST.GFM", 1);
    if( hFile < 1 ) {
        ShowMessage("open gfm error:"+SysErrorMessage(GetLastError()));
        return;
    }
    THandleStream *ths = new THandleStream(hFile);
Then use ths->Write/Read, but it doesn't seem to work.

Using FileRead/Write doesn't seem to work either.

Can someone give an example?
Thanks in advance.
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

You need to use MapViewOfFile. If there's a type conflict, a simple type conversion should help. In Delphi file handles are simple dwords.
Post Reply