开发者

Screen shot program compiling issue

开发者 https://www.devze.com 2023-03-24 12:51 出处:网络
I am trying to get this screen shot program to work (below) which saves a picture of the screen as a bmp file and when I try to compile it using gcc, I get the following error:

I am trying to get this screen shot program to work (below) which saves a picture of the screen as a bmp file and when I try to compile it using gcc, I get the following error:

/tmp/ccetmoRd.o:Screenshot.c:(.text+0x128): undefined reference to _GetDIBits@28' /tmp/ccetmoRd.o:Screenshot.c:(.text+0x1e1): undefined reference to_GetDIBits@28' collect2: ld returned 1 exit status

Any ideas why this may be?

Thanks a lot.

code:

#include <stdlib.h>
#include <windows.h>
#include <stdio.h>

void TakeScreenShot(char* filename);

int main()
{
   TakeScreenShot("c:\\Screenshot.bmp");
   return 0;
}

//
// Side Effects:N/A
//
//This code is copyrighted and has// limited warranties.Please see http://
//   www.Planet-Source-Code.com/vb/scripts/Sh
//   owCode.asp?txtCodeId=10754&lngWId=3//for details.//**************************************
// 

void TakeScreenShot(char* filename)
{
   keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
   keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
   HBITMAP h;        

   OpenClipboard(NULL);
   h = (HBITMAP)GetClipboardData(CF_BITMAP);
   CloseClipboard();
   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,h,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,h,0,bmpInfo.bmiHeader.biHeight,pBuf, &bmpInfo, DIB_RGB_COLORS);

      if((fp = fopen(filename,"wb"))==NULL)
      {
         MessageBox(NULL, "Unable to Create Bitmap File", "Error", MB_OK|MB_ICONERROR);
         break;
      }

      bmpFile开发者_如何学运维Header.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(0);

   if(hdc)
      ReleaseDC(NULL,hdc);
   if(pBuf)
      free(pBuf);

   if(fp)
      fclose(fp);
}


Since feature requests to mark a comment as an answer remain declined, I copy the above solution here.

SOLVED: Downloaded gdi32 library and it resolved the issue. Thanks for the tip! – Jeremy

0

精彩评论

暂无评论...
验证码 换一张
取 消