I need to understand if and how the win32 API SetDIBitsToDevice() allocates extra memory buffers during its process

Anders Kofoed 20 Reputation points
2025-06-12T10:27:17.5233333+00:00

Hi,

I could not find an appropriate tag for my problem so I selected the one I felt was most likely to give me relevant response.

I am currently working with an application in which it is extremely important that no copies of any data is retained in memory. This also include images that we obtain through a camara. We need to display those images to the user but must make sure that all traces of the image data is gone after we are done with it. We therefore are considering using SetDIBitsToDevice() to display the image in a win32 window.

Our main concern at the moment is how SetDIBitsToDevice() actually perform this process and what buffers it creates for this process and what happens to the content of those buffers after a call. Any help on this subject would be greatly appreciated

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,960 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,191 Reputation points
    2025-06-13T08:26:02.07+00:00

    SetDIBitsToDevice allocates buffers for lpvBits and lpbmi with RtlAllocateHeap and free them with RtlFreeHeap

    (when memory is not freed, MSDN usually adds "The caller is responsible for freeing the memory allocated...")


1 additional answer

Sort by: Newest
  1. Bruce (SqlWork.com) 77,476 Reputation points Volunteer Moderator
    2025-06-12T16:01:05.9233333+00:00

    the implementation is up to the video device driver. but in the end the image is copied to video frame buffer and the winapi allows a program to capture the frame buffer contents. this is how screen snapshot programs work. an advanced user you use video drive traces to detailed info of what is sent to driver. There are also video drivers designed to capture video frames

    your best bet is to watermark the images, so you can trace misuse..

    note: if you control the group policies of the computers you can disable snapshot support. basically unless you control the hardware and software configuration of the devices, the user can get snapshots.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.