Create and use a VC Dynamic Link Library

Source: Internet
Author: User

1. MFC extension DLL
Create:
1. Create an MFC extension DLL named dll5 and add the header file named dll5.
2. Add the following content to the header file:
Extern _ declspec (dllexport) cstring concata (cstring X, cstring y );
3. Add the following to the CPP file:
Extern _ declspec (dllexport) cstring concata (cstring X, cstring y)
{
Return X + Y;
}
4. Add the following to the CPP file:
# Include "dll5.h"

5. compile and generate the DLL
Usage:
1. Create a single-document applicationProgram, Named usedll5
2. Copy the generated dll5.lib file and dll5.h file to the current application path,
Copy the dll5.dll file to debug under the current application.
3. Add the following statement to the file (or class) where the dll5 export method (concata) is used in the current application:
# Include "dll5.h"
Suppose you want to add it to usedll5view. cpp.
4. Create a message ing entry in the usedll5view class and add the following statement to the message function:
Cstring A = concata ("China North Vehicle Group", "Changchun Railway Passenger Car Co., Ltd ");
MessageBox ();
5. Add dll5.lib to the project/Setup/connection/Object Library/module.

6. Compile and execute the application and trigger the message. The output is as follows:

China North Vehicle Group Changchun Railway Passenger Car Co., Ltd.

Then, as long as the definition is not changed, no matter how the function body is changed. We only need to copy the compiled DLL. If the definition has been modified, You need to copy the H and Lib files and re-compile them.

Ii. Use the shared mfc dll for the Dynamic Link Library
Create:
1. Create a DLL (select Dynamic Link Library and use the shared mfc dll)
2. Add the following content to the header file:
_ Declspec (dllexport) cstring winapi concata (cstring X, cstring y );
3. Add the following content to the end of the CPP file:
_ Declspec (dllexport) cstring winapi concata (cstring X, cstring y)
{
Return X + Y;
}
4. compile and generate the DLL
Usage:
1. Create a single-document application named usedll8
2. Copy the generated dll8.lib file to the current application path,
Copy the dll8.dll file to C:/winnt/system32.
3. Add the following statement to the header file of the class using the dll5 export method (concata) in the current application:
Extern cstring winapi concata (cstring X, cstring y );
Suppose you want to add it to usedll8view. h.
4. Create a message ing entry in the usedll8view class and add the following statement to the message function:
Cstring A = concata ("China North Vehicle Group", "Changchun Railway Passenger Car Co., Ltd ");
MessageBox ();
5. Add dll8.lib to the project/Setup/connection/Object Library/module.
6. Compile and execute the application and trigger the message. The output is as follows:

China North Vehicle Group Changchun Railway Passenger Car Co., Ltd.

 

 

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.