Solved

File mapping HBITMAP.

Posted on 2004-04-14
1
919 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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

762 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

6 Experts available now in Live!

Get 1:1 Help Now