Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// Open our private block
//-----------------------------------------------------------------------------
HRESULT IPCReaderInterface::OpenPrivateBlockOnPid(DWORD pid, DWORD dwDesiredAccess)
{
	HRESULT hr	= NO_ERROR;
	DWORD dwErr = 0;

	

	WCHAR szMemFileName[100];
	IPCShared::GenerateName(pid, szMemFileName, 100);


// Note: if our private block is open, we shouldn't be attaching to a new one.
	_ASSERTE(!IsPrivateBlockOpen());
	if (IsPrivateBlockOpen()) 
	{
		return ERROR_ALREADY_EXISTS;
	}

	m_handlePrivateBlock = WszOpenFileMapping(dwDesiredAccess,
                                              FALSE,
                                              szMemFileName);
    
	dwErr = GetLastError();
    if (m_handlePrivateBlock == NULL)
    {
        hr = HRESULT_FROM_WIN32(dwErr);
        goto errExit;
    }

    
	m_ptrPrivateBlock = (PrivateIPCControlBlock*) MapViewOfFile(
		m_handlePrivateBlock,
		dwDesiredAccess,
		0, 0, 0);

	dwErr = GetLastError();
    if (m_ptrPrivateBlock== NULL)
    {
        hr = HRESULT_FROM_WIN32(dwErr);
        goto errExit;
    }

// Client must connect their pointers by calling GetXXXBlock() functions

errExit:
	if (!SUCCEEDED(hr))
	{
		ClosePrivateBlock();	
	}

	return hr;
}
//-----------------------------------------------------------------------------
// dtor
//-----------------------------------------------------------------------------
IPCReaderInterface::~IPCReaderInterface()
{
    LEAF_CONTRACT;

    LOG((LF_CORDB, LL_INFO10, "IPCRI::IPCReaderInterface::~IPCReaderInterface 0x%08x\n", m_handlePrivateBlock));
    LOG((LF_CORDB, LL_INFO10, "IPCRI::IPCReaderInterface::~IPCReaderInterface 0x%08x (Public)\n", m_handlePublicBlock));

    if (m_handlePrivateBlock)
    {
        ClosePrivateBlock();
    }
    _ASSERTE(m_handlePrivateBlock == NULL);
    _ASSERTE(m_ptrPrivateBlock == NULL);

    if (m_handlePublicBlock)
    {
        ClosePublicBlock();
    }
    _ASSERTE(m_handlePublicBlock == NULL);
    _ASSERTE(m_ptrPublicBlock == NULL);

}