Solved

File mapping HBITMAP.

Posted on 2004-04-14
1
969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

705 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