PC Review


Reply
Thread Tools Rate Thread

Duplicating GDI Objects

 
 
Christopher McKay
Guest
Posts: n/a
 
      25th Feb 2004
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?
 
Reply With Quote
 
 
 
 
John Phillips
Guest
Posts: n/a
 
      25th Feb 2004
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?



 
Reply With Quote
 
Christopher McKay
Guest
Posts: n/a
 
      25th Feb 2004
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?

>
>
>

 
Reply With Quote
 
John Phillips
Guest
Posts: n/a
 
      25th Feb 2004
Hmm...can't seem to find where in MSDN it says you -=can't=- do this, but
the prevailing wisdom in microsoft.public.platoformsdk.gdi appears to be
that one cannot.

It would seem that the best workaround is to use CreateDIBSection() and use
file mapping.

--
John Phillips
MVP - Windows SDK



"Christopher McKay" <no_cmckay70_spam@no_hotmail_spam.com> wrote in message
news:#AgYmX8#(E-Mail Removed)...
> 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?

> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
objects duplicating in Tab =?Utf-8?B?QnJldA==?= Microsoft Access Forms 1 31st Aug 2007 03:48 AM
100% Free MS Access .NET Code Generator (tired of hand cranking business objects/data objects) ? MyGeneration Microsoft Access 0 27th Jan 2005 04:55 AM
Duplicating Objects =?Utf-8?B?RWRC?= Microsoft VB .NET 11 30th Nov 2004 05:29 PM
AD duplicating printer objects Paul Barclay Microsoft Windows 2000 Printing 0 3rd Dec 2003 04:32 PM
Tasks duplicating/Contacts duplicating Kathryn Ingram Microsoft Outlook 0 8th Aug 2003 04:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:00 PM.