Code Comments
Programming Forum and web based access to our favorite programming groups.Hello everyone,
This is a pretty tricky question for C/Labview people. I am trying to
BitBlt to an OpenLabview window, and to do this I need to grab the Device Co
ntext of the window front panel that I would like to write to. The Bit
Blt is succesful, but after
several thousand updates (5000 - 10000) Labview crashes. I have t
raced it down to the GetDC command. If this command is executed, Labvi
ew will crash 100% of the time. If the command is removed, Labview wil
l not crash (but doesn't w
ork because BitBlt doesn't know which window to write to). Does anyone
know what is causing this? C code is as follows:
__declspec( dllexport) float WriteToFrontPanel(unsigned int *ptrRGB)
{
HWND Labview;
BITMAPV4HEADER bih;
ZeroMemory(&bih, sizeof(BITMAPV4HEADER));
bih.bV4Size = sizeof(BITMAPV4HEADER);
bih.bV4Width = 1000;
bih.bV4Height = -1000;
bih.bV4Planes = 1;
bih.bV4BitCount = 32;
bih.bV4V4Compression = BI_RGB;
int temp = 0;
Labview = FindWindow(NULL, "Window.vi");
HDC bit_dc = CreateCompatibleDC(NULL);
HBITMAP hBit = CreateDIBitmap(GetDC(Labview), (LPBITMAPINFOHEADER)&bih,
CBM_INIT, ptrRGB, (LPBITMAPINFO)&bih, DIB_RGB_COLORS);
SelectObject(bit_dc, hBit);
BitBlt(GetDC(Labview), 0, 0, 1000, 1000, bit_dc, 0, 0, SRCCOPY);
temp = ReleaseDC(Labview, GetDC(Labview));
DeleteDC(bit_dc);
DeleteObject(hBit);
return temp;
}
The function commands and descriptions are at <a href="http://www.msdn.com/" target="_b
lank">www.msdn.com</a> if anyone is interested in following the discussion.
Thanks for your time,
AustinMessage Edited by AustinMcElroy on 02-28-2008 02:24 PM
Post Follow-up to this messageHi, You have this solved, but I'll comment on it anyway... Seems to me you open three DC's with GetDC. Once in CreateDIBitmap, once in BitBlt, once in ReleaseDC. You close the reference once in ReleaseDC. I'm not a C expert, but I think all three of the GetDC return a differente reference! Could you comment on your solution (I'm not going to use it anytime soon, but other reader might)? Btw. If I recall correctly, the GetDC is very slow. You could try to buffer it, and only use GetDC when the old one causes an error when used. Regards, Wiebe.
Post Follow-up to this messageAustin (or Weibe), I think I'm having a similar problem, but I do not follow your solution since I'm not familiar with C. Could you attach a VI that illustrates how you create hTempDC that is equal to GetDC (LabVIEW)? How do you k now if the temporary DC exp ires (or does it not expire in your application)? How do you destroy t he DC when you are finished (that is, if Weibe is correct and ReleaseDC crea tes another DC... Am I missing something?)? Thanks!Jason
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.