简体   繁体   English

屏幕截图程序编译问题

[英]Screen shot program compiling issue

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: 我试图使该屏幕截图程序正常工作(如下),该程序将屏幕图片另存为bmp文件,当我尝试使用gcc对其进行编译时,出现以下错误:

/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 /tmp/ccetmoRd.o:Screenshot.c:(.text+0x128):对_GetDIBits@28' /tmp/ccetmoRd.o:Screenshot.c:(.text+0x1e1): undefined reference to _GetDIBits @ 28'的_GetDIBits@28' /tmp/ccetmoRd.o:Screenshot.c:(.text+0x1e1): undefined reference to collect2:ld返回1退出状态

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;
      }

      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(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. 已解决:下载了gdi32库,它解决了该问题。 Thanks for the tip! 谢谢你的提示! – Jeremy –杰里米

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM