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.