Introduction to some common precompiling commands in Vc ++ Compilers

Source: Internet
Author: User

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



 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.