我如何将kernel32.lib,user32.lib,gdi32.lib,comdlg32.lib,库链接到我的C ++ [英] How do i link kernel32.lib, user32.lib, gdi32.lib, comdlg32.lib, libraries to my c++

查看:444
本文介绍了我如何将kernel32.lib,user32.lib,gdi32.lib,comdlg32.lib,库链接到我的C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要链接的库:

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

并添加头文件

Windows.h

谢谢


Libraries to link in:

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

and adding a header file

Windows.h

Thanks


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

推荐答案

如果您使用的是Visual Studio IDE(仅此而已),则无需考虑它们.如果打开项目属性,您将看到所有这些属性都已添加到要编译的项目中.默认情况下,将链接此文件中使用的功能.

但是如果要链接其他库(例如commctrl.lib),则必须通过property(Alt + F7)将其包括在内,然后按照配置Property>>> Linker>> Input

然后编写库名称.
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.


仅适用于Microsoft Visual Studio:
Microsoft Visual Studio only:
#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
}


两种解决方法,请参阅解决方案1和解决方案2.
Two way to solve it.Please see solution 1 and solution 2.


这篇关于我如何将kernel32.lib,user32.lib,gdi32.lib,comdlg32.lib,库链接到我的C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆