Solved

File mapping HBITMAP.

Posted on 2004-04-14
1
933 Views
Last Modified: 2013-11-20
Hi,

   I want to pass a HBITMAP from one process to another using memory mapped file. Given the HBITMAP object, is it possible to copy the entire object into the memory mapped buffer so that the other project can see it? How do I copy the entire HBITMAP into the memory buffer and how to retrieve it?

Thanks.

0
Comment
Question by:pcssecure
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 10822000
HBITMAP handle cannot be passed to another process. To pass all bitmap data you need device-independent bitmap (DIB). This means, bitmap must be created using CreateDIBSection function. Device-depended bitmap (DDP), created by CreateCompatibleBitmap function, cannot be saved or copied to memory block.
Advantage of DIB is that it allows direct access to bitmap bits (array of pixels). It may be accessed using GetBitmapBits and SetBitmapBits API.
Having DIB handle, you can save all bitmap data using one of the following ways:

1) If both sender and receiver know bitmap format (for example, RGB 24 bits per pixels), only bitmap bits may be copied to memory-mapped file.
For example, we have 24 bpp RGB DIB with 100*100 size. Sender creates DIB using CreateDIBSection and fills bitmap by some way. Memory block required for this bitmap bits must have 100*100*3 bytes size. Let's say that:
void* pMapping - pointer to shared memory block
HBITMAP hDIB - DIB handle.

To copy bitmap bits to memory block sender executes the following code:

GetBitmapBits(hDIB, 100*100*3, pMapping);

Receiver creates DIB by the same way as sender.
void* pMapping - pointer to shared memory block (the same as receiver)
HBITMAP hDIB - DIB handle (created, bit not filled).

To read bitmap bits from the shared memory block receiver executes the following code:

SetBitmapBits(hDIB, 100*100*3, pMapping);

2) If bitmap parameters (color depth, dimensions etc.) are unknown to receiver, it's better to write bitmap in BMP format to shared memory block. To do this sender should fill and write the following information:
- BITMAPFILEHEADER structure;
- BITMAPINFOHEADER structure;
- color palette (for RGB files it is not necessary);
- bitmap bits, as in p.1.

Receiver reads this memory block, creates it's own DIB according to information in BITMAPINFOHEADER, and fills bitmap bits like in p.1.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sameEnds challenge 3 134
viewing source code from eclipse 13 88
zeroMAx challenge 20 88
noX challenge 17 92
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now