Solved

File mapping HBITMAP.

Posted on 2004-04-14
1
957 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 72
sumDigits challenge 9 172
bigDiff challenge 17 134
mapAB Challlenge 35 173
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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