Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

GetDC and BitBlt in Labview C DLL
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

Report this thread to moderator Post Follow-up to this message
Old Post
AustinMcElroy
02-29-08 03:16 AM


Re: GetDC and BitBlt in Labview C DLL
Hi,

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.



Report this thread to moderator Post Follow-up to this message
Old Post
Wiebe@CARYA
02-29-08 01:20 PM


Re: GetDC and BitBlt in Labview C DLL
Austin (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

Report this thread to moderator Post Follow-up to this message
Old Post
LabBEAN
04-03-08 01:39 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

LabVIEW archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 12:48 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.