From the
MSDN library (see
http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx[
^]):
Return Values
If the function succeeds, the return value is a handle to the file mapping object.
If the object exists before the function call, the function returns a handle to the existing object (with its current size, not the specified size), and
GetLastError
returns
ERROR_ALREADY_EXISTS
.
If the function fails, the return value is
NULL
. To get extended error information, call
GetLastError
.
Then you should do the following:
- call
CreateFileMapping
to get an handle to the object required
- if the returned handle is
NULL
, call GetLastError
to get extended informations about the failure
- if the returned handle is not
NULL
call GetLastError
and test the returned code: if the code is ERROR_ALREADY_EXISTS
, then you have got an handle to a shared object that already exists, otherwise the object has been created for the first time