Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Vote on your favorite hash algorithm here!

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-15-2008, 10:30 AM
bubba_169 bubba_169 is offline
Newbie
 
Join Date: Jun 2008
Posts: 1
Credits: 0
Rep Power: 0
bubba_169 is on a distinguished road
Default No more than 23???

Ok I ran into a problem and Im pulling my hair out trying to get around it. Im writing a small screen capture program that saves the bitmaps to disk, here is a simplified source of what im trying to do...


Code:
#include <windows.h>
#include <stdio.h>

//Copied from www(dot)geocities(dot)com/krishnapg/bitmap.html
void SaveBitmap(char *szFilename,HBITMAP hBitmap)
{
      HDC        hdc=NULL;
      FILE*      fp=NULL;
      LPVOID     pBuf=NULL;
      BITMAPINFO bmpInfo;
      BITMAPFILEHEADER  bmpFileHeader; 
      do{ 
            hdc=GetDC(NULL);
            ZeroMemory(&bmpInfo,sizeof(BITMAPINFO));
            bmpInfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
            GetDIBits(hdc,hBitmap,0,0,NULL,&bmpInfo,DIB_RGB_COLORS); 
            if(bmpInfo.bmiHeader.biSizeImage<=0)
				bmpInfo.bmiHeader.biSizeImage=bmpInfo.bmiHeader.biWidth*abs(bmpInfo.bmiHeader.biHeight)*
				(bmpInfo.bmiHeader.biBitCount+7)/8;

            if((pBuf = malloc(bmpInfo.bmiHeader.biSizeImage))==NULL)
            {
                  MessageBox( NULL, "Unable to Allocate Bitmap Memory", "Error", MB_OK|MB_ICONERROR);
                  break;
            }            
            bmpInfo.bmiHeader.biCompression=BI_RGB;
            GetDIBits(hdc,hBitmap,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);       
            if((fp = fopen(szFilename,"wb"))==NULL)
            {
                  MessageBox( NULL, "Unable to Create Bitmap File", "Error", MB_OK|MB_ICONERROR);
                  break;
            } 

            bmpFileHeader.bfReserved1=0;
            bmpFileHeader.bfReserved2=0;
            bmpFileHeader.bfSize=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bmpInfo.bmiHeader.biSizeImage;
            bmpFileHeader.bfType='MB';
            bmpFileHeader.bfOffBits=sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER); 
            fwrite(&bmpFileHeader,sizeof(BITMAPFILEHEADER),1,fp);
            fwrite(&bmpInfo.bmiHeader,sizeof(BITMAPINFOHEADER),1,fp);
            fwrite(pBuf,bmpInfo.bmiHeader.biSizeImage,1,fp); 

      }while(FALSE); 
            if(hdc)     ReleaseDC(NULL,hdc); 
            if(pBuf)    free(pBuf); 
            if(fp)      fclose(fp);
}

int WinMain(HINSTANCE h, HINSTANCE hp, LPSTR c, INT s){
	int i;
	for(i=1; i<=30; i++){
                //Capture the screen
		HDC dc = GetDC(NULL);
		HDC cdc = CreateCompatibleDC(dc);
		HBITMAP screen = CreateCompatibleBitmap(dc, 1280, 1024);
		HBITMAP dummy = SelectObject(cdc, screen);
		BitBlt(cdc, 0, 0, 1280, 1024, dc, 0, 0, SRCCOPY);
		screen = SelectObject(cdc, dummy);

		char TEMPFILE[255];
		sprintf(TEMPFILE, "c:/bmp%i.bmp", i);
		
                //Save the HBITMAP to disk
		SaveBitmap(TEMPFILE, screen);
	
		DeleteObject(screen);
		DeleteDC(cdc);
		ReleaseDC(NULL, dc);
	}
	return 0;
	
}
This code works fine and captures the full screen up to 23 times, after that it only creates 1kb bitmap files with a 0x0 resolution. Just to clarify, the first 23 runs through the 'for' loop work perfect but after that it just loses it and saves empty files and shows no error.

If anyone can help me get more than 23 runs out of this I would be grateful
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-16-2008, 10:57 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,535
Last Blog:
wxWidgets is NOT code ...
Credits: 919
Rep Power: 28
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default Re: No more than 23???

It looks like you aren't closing your files... you may be hitting a resource limit.
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum
Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 08:44 PM.

Contest Stats

Xav ........ 1357.94
MeTh0Dz|Reb0rn ........ 1075.89
WingedPanther ........ 919.18
marwex89 ........ 906.86
morefood2001 ........ 900.18
John ........ 890.77
Brandon W ........ 770.65
chili5 ........ 312.39
Steve.L ........ 264.99
dcs ........ 232.34

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 83%

Ads