Here's the code that I am currently using:
HANDLE hProc = ::OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE,
pid);
HBITMAP hBit;
// Request the bitmap handle from the second process
if( !:

uplicateHandle(hProc, (HANDLE)::SendMessage(hwnd, WM_USER + 10,
0, 0), ::GetCurrentProcess(), &hBit, 0, FALSE, DUPLICATE_SAME_ACCESS) ) {
TCHAR msg[256];
::FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
msg, 256, NULL);
::MessageBox(m_hWnd, msg, _T("Results"), MB_ICONERROR);
}
else
::CloseHandle(hBit);
::CloseHandle(hProc);
The problem I am always having is that DuplicateHandle fails with the
message, "The handle is invalid". The only thing I can think of is that
the DuplicateHandle routine will not duplicate the GDI handle being
returned by my message handler. That's why I'm not sure what to do next.
Thanks for your help.
Chris McKay
John Phillips wrote:
> What makes you think that you can't use DuplicateHandle()? Do you get an
> error when you do so? If so, can you show how you're calling it?
>
> Haven't tried this myself, but it would seem that the 2nd last paragraph of
> Q106386 suggests that DuplicateHandle() is the way to go.
>
>
> --
> John Phillips
> MVP - Windows SDK
>
>
> "Christopher McKay" <no_cmckay70_spam@no_hotmail_spam.com> wrote in message
> news:uMNeBYz#(E-Mail Removed)...
>
>>I hope that there is an answer for this. I have a process that contains
>>an HBITMAP. I want to share that object with another process. It
>>appears that I cannot use the DuplicateHandle API to make a copy of the
>>bitmap for my second process.
>>
>>Is there a way where I can copy GDI objects from one process to another?
>
>
>