We are usingCodeA large number of precompiling commands are often seen. This article explains the functions of Common commands.
1 # pragma once
This command is unique to the VC compiler and is used to compile the header file only once. Its role is equivalent to the traditional macro:
# Ifndef headfile_h
# Define headfile_h
Header file Definition
# Endif
In a project, different header files are often referenced from each other. If this command is not added, it is likely that a header file will be referenced multiple times in a file, resulting in an error. After this command is added, the header file can be referenced and compiled only once.
For example:
// Assume that the header file is defined as classa. h.
# Pragma once
Class
{
Public:
Virtual void F (){}
};
It is equivalent
# Ifndef classa_h
# Define classa_h
Class
{
Public:
Virtual void F (){}
};
# Endif
# Pragma comment (Lib, "XXXX. lib ")
This command is used to convert XXXX. the LIB library file package is included in the project for compilation. The equivalent method is to set the file package in vc6.0> Project> setting> link> Object/library to xxxx. lib. We know that there are two types of DLL calls, one is implicit call (implicit calss), that is, static call ), this call method requires that the entry address of the DLL object and method in the corresponding lib file be provided during compilation, so the Lib file must be included. The other method is explicit call. To call a function in a DLL, you need to take three steps:
Handle H = loadlibrary (dllname) --> getprocaddress (H, functionname) returns the function pointer and calls its function through the function pointer --> freelibrary (h)
For example, another. dll has an int add (int x, int y) function. The complete call process is as follows:
Typedef int (* funptr) (INT, INT); // defines the function pointer
Funptr;
Handle H = loadlibrary ("another. dll ");
Funptr = (funptr) getprocaddress (H, "add ");
Funptr (2, 3); // 2 + 3;
Freelibrary (h );
Of course, this method does not require the Lib file.
_ Declspec (dllexport ):
Generally used as: # define dll_export _ declspec (dllexport)
SeeArticle: Http://www.cnblogs.com/Winston/archive/2008/07/05/1236273.html
_ Stdcall and _ cdecl
Please refer to the article:
Http://www.cnblogs.com/Winston/archive/2008/09/11/1289391.html