Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to share transient data between instances of a DLL by means of File Mapping. The first time this is done, everything needs to be initialised. How does an instance know whether CreateFileMapping() actually creates the object, or alternatively maps an existing object?
Posted
Updated 23-May-10 14:08pm
v2

1 solution

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

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900