Gdi32lib.h

closed account (N8MNAqkS)
So I am trying to use the setpixel function but I need a library Gdi32lib.h and a DLL Gdi32.dll.


first off, I am very new to c++ so don't judge me on these next few questions.


1. what is a DLL.


2. how do I get that DLL.


3. how do I get that library.


if I was supposed to download it when I got Visual studio, I guess I didn't, in which case where do I go to get it if I boched the download in the first place.

also it gives me this error

Severity Code Description Project File Line Suppression State
Error (active) E0337 linkage specification is incompatible with previous "SetPixel" (declared at line 4575 of "C:\Program Files\Windows Kits\10\Include\10.0.17763.0\um\wingdi.h") testNo.2
Last edited on
Gdi32.dll already exists on your system. (It is a core Windows component.)

You may not have gdi32.lib. (This is part of your compiler’s development environment.) If you do not, or if you are not sure:

(1)
Visual studio does not automatically come with everything necessary to compile and execute C++ and Win32 code.

Restart your VS installer and make sure that you have the “Desktop Development with C++” and “Windows API/SDK” (or whatever it is called) selected, then continue. This will update your environment.

(2)
Before you compile, go to your project options and add “Gdi32” in the list of libraries to link with your executable. VS will not do this automatically for you.

If you wish to be more general, somewhere near the top of your main source file (.cpp), add:

 
  #pragma comment( lib, "gdi32" ) 

This tells MSVC (and GCC as well) to link with the Gdi32 library.

Hope this helps.
closed account (N8MNAqkS)
thanks for responding.

first off, im not sure if I did what u said. I opened VS installer and ended up updating it, and then updating visual studio community 2017(which is the thing I use to program) and just incase that's not what you told me to do, how do I restart the installer.
That was it. Did you get to the part in step 3 here?
https://docs.microsoft.com/en-us/cpp/build/vscpp-step-0-installation?view=vs-2017
closed account (N8MNAqkS)
ok yes that is what I did, and I selected the desktop development with c++ and a thing called SDK.


although where are the project options u are talking about to add Gdi32.

here is my program if it helps

#include "pch.h"
#include <iostream>
#include <string>
#include <Windows.h>
#pragma comment( lib, "gdi32" )
using namespace std;

int main()
{

COLORREF SetPixel(
HDC hdc,
int x,
int y,
COLORREF color
);

return 0;
}




this one actually executes, but wont print anything to the screen

SetPixelV(NULL, 0, 0, RGB(255, 255, 255));

why?
Last edited on
You need a selected and active DC to use SetPixel().

I suggest you find yourself a tutorial on Win32 GDI programming (not GDI+, as that is something different).

A very good place to start is (theForger's Win32 API Tutorial|http://www.winprog.org/tutorial/), which will get you to the point of having a window and being able to create a bitmap and access the GDI device context.

Hope this helps.
closed account (N8MNAqkS)
thank you.

but what is a DC

also the link u provided me will be of no use as I am leaning C++ and are not currently learning C.
Last edited on
A DC is a device context. This is explained in the link.

If you want to learn to push pixels in a Win32 application, you must learn Win32. I have given you the correct tutorial.

If you are studying C++ in school or something, I suggest you be careful not to get too distracted by non-course material. Stick with what is necessary to understand the course objectives, and save doing cool extra stuff for personal projects on your own time.
Topic archived. No new replies allowed.