Member Avatar

Hi there, I want to make a program with visual C++ 2010 using windows form.
My problem is that I want to include "windows.h" and I can't find out how to do that.
I want to include "windows.h" to use functions such as SetPixel() and some others...

If it's possible, where to I include "windows.h"?

Recommended Answers

Just add the include statement to the top of the source file, which will use the functions from windows.h :

#include <windows.h>
Jump to Post

The problem really isn't how to include windows.h but how to get the HDC parameter that most win32 api graphics functions require. I don't know how to get that either from managed code.

Jump to Post

Those errors occure when you are not linking to a library that is required.

You will need to link to the win32 libs

Here are a few that I can remember:

ole32.lib
comctl32.lib
advapi32.lib
user32.lib

Hope that helps!

Jump to Post

All 10 Replies

Just add the include statement to the top of the source file, which will use the functions from windows.h :

#include <windows.h>

The problem really isn't how to include windows.h but how to get the HDC parameter that most win32 api graphics functions require. I don't know how to get that either from managed code.

Member Avatar

Just add the include statement to the top of the source file, which will use the functions from windows.h :

#include <windows.h>

I tried but it wasn't able to build it and it gave me errors.

costume crosshair.obj : error LNK2028: unresolved token (0A00000F) "extern "C" unsigned long __stdcall SetPixel(struct HDC__ *,int,int,unsigned long)" (?SetPixel@@$$J216YGKPAUHDC__@@HHK@Z) referenced in function "private: void __clrcall costumercrosshair::Form1::btn_start_Click(class System::Object ^,class System::EventArgs ^)" (?btn_start_Click@Form1@costumercrosshair@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
costume crosshair.obj : error LNK2028: unresolved token (0A000010) "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "private: void __clrcall costumercrosshair::Form1::btn_start_Click(class System::Object ^,class System::EventArgs ^)" (?btn_start_Click@Form1@costumercrosshair@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
costume crosshair.obj : error LNK2019: unresolved external symbol "extern "C" unsigned long __stdcall SetPixel(struct HDC__ *,int,int,unsigned long)" (?SetPixel@@$$J216YGKPAUHDC__@@HHK@Z) referenced in function "private: void __clrcall costumercrosshair::Form1::btn_start_Click(class System::Object ^,class System::EventArgs ^)" (?btn_start_Click@Form1@costumercrosshair@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
costume crosshair.obj : error LNK2019: unresolved external symbol "extern "C" struct HDC__ * __stdcall GetDC(struct HWND__ *)" (?GetDC@@$$J14YGPAUHDC__@@PAUHWND__@@@Z) referenced in function "private: void __clrcall costumercrosshair::Form1::btn_start_Click(class System::Object ^,class System::EventArgs ^)" (?btn_start_Click@Form1@costumercrosshair@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)

Those errors occure when you are not linking to a library that is required.

You will need to link to the win32 libs

Here are a few that I can remember:

ole32.lib
comctl32.lib
advapi32.lib
user32.lib

Hope that helps!

Member Avatar

Those errors occure when you are not linking to a library that is required.

You will need to link to the win32 libs

Here are a few that I can remember:

ole32.lib
comctl32.lib
advapi32.lib
user32.lib

Hope that helps!

hmm, I remember I saw at MSDN Library, like here
under "Requirements" there is a table and a name of the name of the .lib i need to include to use that function, right?

and how do I link them? I tried to include them but it says it cant find them.

Under the Project menu: choose <projectname> Properties. Go to Configuration Properties. Under Linker/General: fill in the Additional Library Directories and under Linker/Input: fill in the Additional Dependencies with the .lib names

Member Avatar

Under the Project menu: choose <projectname> Properties. Go to Configuration Properties. Under Linker/General: fill in the Additional Library Directories and under Linker/Input: fill in the Additional Dependencies with the .lib names

How do I find the Library Directories path? lets say gdi32.lib?

Hi i have a few VS installs here and some other sdk's so im not sure which is right but i find allot of them at "C:\Program Files\Microsoft SDKs\Windows\v7.0\Lib" if this is wrong for you change the version number from v7.0, i also have a V5.0, v6.0A and v7.0A. gdi32.lib is in all of my versions (didnt look at 5 or 6).

Hope that helps :)

I'm not sure, but I think that the libs were added to your path when Visual Studio installed. So, just add "gdi32.lib" and any other necessary libs to the linker settings.

Hope that helps :)

Member Avatar

First of all, thank you all!

I found the solution, I had to include the window.h header in a file called "stdafx.h".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.