Memory stream for bitmap

B

botched

I have the following code w/is working like a champ. Problem is I dont want
to write it to file yet. I would rather write it to memory and pass a
HBITMAP handle back to the calling process. So far I my attempt has only
yeilded memory issues. Can someone point me to the right direction.

long nBufferSize = am_media_type.lSampleSize;
long *pBuffer = (long *)malloc(nBufferSize);

HANDLE fh;
BITMAPFILEHEADER bmfh;
DWORD nWritten;
memset(&bmfh, 0, sizeof(bmfh));
bmfh.bfType = ('M' << 8) | 'B';
bmfh.bfSize = sizeof(bmfh) + sizeof(BITMAPINFOHEADER) + nBufferSize;
bmfh.bfOffBits = sizeof(bmfh) + sizeof(BITMAPINFOHEADER);

fh = CreateFile(L"sample.bmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(fh, &bmfh, sizeof(bmfh), &nWritten, NULL);
WriteFile(fh, &pVideoInfoHeader->bmiHeader, sizeof(BITMAPINFOHEADER),
&nWritten, NULL);
WriteFile(fh, pBuffer, nBufferSize, &nWritten, NULL);
CloseHandle(fh);

GlobalFreePtr(&pVideoInfoHeader);
GlobalFree(&bmfh);
free(pBuffer);
nBufferSize = NULL;
 
M

Michael Phillips, Jr.

I would rather write it to memory and pass a HBITMAP handle back to the
calling process.

Use may use CreateStreamOnHGlobal to write the bitmap to a chunk of global
memory.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top