If you dynamically use the APIS provided by the Platform

Source: Internet
Author: User

The development tool installation directory contains the include and Lib directories, which store the API declarations provided by the OS and encapsulated classes for convenience.ProgramMost of the services provided by encapsulated classes are implemented by calling the OS APIs, but the actual OS APIs are implemented in one DLL. When we want to use these Apis or encapsulated class services, the general practice is as follows:

// Test. cpp

# Include <XXX. h>

# Param comment (Lib, "XXX. lib ")

// Call an API or use an encapsulated class

The program developed using the above method cannot work normally in any system, because when executing this program, the system dynamically loads the various DLL used by the system, these DLL Programs depend on may not always exist in the system, such as gdiplus. DLL does not exist in 2000 by default. When loading fails, the program may be faulty.

A solution is to include the DLL that the program depends on in the installation package of the program, but this will increase the installation package.

Another solution is: if you can allow the loss of some APIs provided by the DLL, you can consider the solution described below.

(1) Remove # Param comment (Lib, "XXX. lib ")

(2) encapsulate APIs

Suppose you use void apifunc1 (); then you provide a void apifunc1 (); Function

The function is implemented as follows:

Void apifunc1 ()

{

Loadlibrary ("XXX. dll ");

If loading fails, or a simplified version is directly returned or implemented by yourself;

If the load is successful, call the real API

}

(3) Some methods provided by some encapsulated classes provided by the development tool call the API directly, and we also change this method. However, most of these encapsulated classes are in the include directory, and the files in this directory cannot be changed at will. What should we do? We only need to follow the 2 method. When the compiler links the API, it links our own program because it finds that the function is implemented in our program.

 

 

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.