Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Libraries to link in:

kernel32.lib, user32.lib, gdi32.lib, comdlg32.lib

and adding a header file

Windows.h

Thanks


C++
#include <windows.h>

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow )
{
	PRINTDLG pd;

	memset( &pd, 0, sizeof( pd ) );

	pd.lStructSize = sizeof( pd );

	/* 
	 * get rid of PD_RETURNDEFAULT on the line below if you'd like to
	 * see the "Printer Settings" dialog!
	 *
	 */
	pd.Flags = PD_RETURNDEFAULT | PD_RETURNDC;

	// try to retrieve the printer DC
	if( !PrintDlg( &pd ) )
	{
		MessageBox( NULL, "PrintDlg( &pd ) failed!", "Fatal Error", MB_OK | MB_ICONERROR );

		return -1;
	}

	DOCINFO di;
	HDC hPrinter = pd.hDC;

	// initialization of the printing!
	memset( &di, 0, sizeof( di ) );
	di.cbSize = sizeof( di );
	StartDoc( hPrinter, &di );

		// start the first and only page
		StartPage( hPrinter );

		// uncomment the following line to print in colour! :)
		// SetTextColor( hPrinter, 0x0000FF );

		// write "Hello, World!" to the printer's DC
		TextOut( hPrinter, 100, 100, "Hello, World!", 13 );

		// finish the first page
		EndPage( hPrinter );

	// end this document and release the printer's DC
	EndDoc( hPrinter );
	DeleteDC( hPrinter );

	return 0;
}
Posted
Comments
[no name] 22-Aug-12 20:48pm    
It's going to depend on the IDE that you are using, or command line compiler.

If you are using Visual Studio IDE(That's all I know) then you don't need to think about them. if you open your project property you will see all of them are already added with your project to be compiled. The function you have used in this file will be linked by default.

but if you want to link other library such as commctrl.lib then you will have to include it through property(Alt+F7) and then follow configuration Property>>Linker>>Input

and then write the library name.
 
Share this answer
 
Comments
Blackdragon_adi 23-Aug-12 11:18am    
I have to link them in Boroland C++
Microsoft Visual Studio only:
C++
#include <windows.h>

#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "comdlg32.lib")

int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow)
{
    // your code
}
 
Share this answer
 
v2
Comments
Blackdragon_adi 23-Aug-12 11:18am    
linking in C++
Two way to solve it.Please see solution 1 and solution 2.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900