| | | | process may subsequently create. In this case, the value of the child's handle is the same as the value of the parent's handle. | | | | | | The DuplicateHandle function is defined as: | | BOOL DuplicateHandle( HANDLE hSourceProcessHandle, // handle to the source process HANDLE hSourceHandle, // handle to duplicate HANDLE hTargetProcessHandle, // handle to process to duplicate to LPHANDLE lpTargetHandle, // pointer to duplicate handle DWORD dwDesiredAccess, // access for duplicate handle BOOL bInheritHandle, // handle inheritance flag DWORD dwOptions // optional actions ); | | | | This function allows a handle in one process to be duplicated into another process. The new process-relative handle in the target process may have a different value than the source handle, but this is of no concern since the handles are process-relative. | | | | | | Many kernel objects can be given a name when they are created. Names are valid system-wise, which means that any other process can access the object by using its name (assuming that it knows the name, of course). For instance, the last parameter in the CreateFileMapping function: | | | | | | HANDLE CreateFileMapping( HANDLE hFile, // handle to file to map LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // optional security attributes DWORD flProtect, // protection for mapping object DWORD dwMaximumSizeHigh, // high-order 32 bits of object size DWORD dwMaximumSizeLow, // low-order 32 bits of object size LPCTSTR lpName // name of file-mapping object ); | | | | | | can be used to specify a name for the file mapping. | | | | | | Assume, for instance, that we have created a file-mapping object named MyFMO. Another process can call OpenFileMapping with this name as its last argument. The function will return a process-relative handle to this object for use by the second process. Alternatively, the second process can call CreateFileMapping, using the object's name as its last argument. The system will see that a file-mapping object by this name already exists and simply return a handle to this object. (This does create a potential problem, because a process may think it is creating a new object when, in fact, it is getting a handle to an existing object. The programmer must check the return value of CreateFileMapping immediately to determine which is the case.) | | |