如何为C ++中的Windows GDI正确设置库?

问题描述 投票:1回答:1

我想制作一个可以实时访问屏幕上像素(颜色和强度,例如位图)的C ++程序。我认为应该可以使用的一种方式是使用Windows的GDI功能,例如CreateCompatibleDC

问题是,当我尝试运行它时,出现错误消息:”C:\ Users \ Myname \ AppData \ Local \ Temp \ cce0hZ9w.o Screencapture_example.cpp :(。text + 0x30):未定义对__imp_CreateCompatibleDC的引用“

所以看起来包含该函数的库似乎不存在或不包括在内。但是我确实包含了windows.h和wingdi.h,并且根据上面给出的链接中的页面,该功能是wingdi.h的一部分。

它还说它需要库Gdi32.lib,该库在我的计算机上找不到。但是,有一个名为libgdi32.a的文件,该文件位于文件夹C:\ Programfiles \ Dev-Cpp \ MinGW64 \ x86_64-w64-mingw32 \ lib中。我下载了gdi32.lib并将其添加到同一文件夹中。重新编译时,错误消息未更改。

该文件夹包含在使用gcc编译器的Dev-C ++编辑器的库部分中。我的操作系统是Windows 10。

#include<windows.h>
#include<wingdi.h>
int main(int argc,char *argv[]){

HDC hdc = GetDC(NULL); // get the desktop device context
HDC hDest = CreateCompatibleDC(hdc); // create a device context to use yourself

//More to come here but I don't want to complicate it too much before
//I get it to work this far.

return 0;
}
c++ windows gcc libraries
1个回答
0
投票

头文件仅提供声明,对于CreateCompatibleDC,您需要提供gdi32.lib作为链接的一部分(这是Microsoft文档页面上Requirements块的“ Library”部分)。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.