How to export the Class Description in the DLL description:
Newly built two projects, one is the DLL project (my sample program is called DLLCLASS), the other is the project of testing and using DLL (name DLLCLASSTEST)
Note: 1. After the DLL engineering compilation, copy the .lib and .dll file to the appropriate directory of the test and use of the DLL project (my program is a release directory), then the leader of the DLL project (hereinafter referred to as header file) ) Copy to the appropriate directory of testing and use of DLL (copy to this project file in my program)
In the directory), then this copy of the header file is then modified by the following 2 and 3.
2. The header file in the DLL project is used. #Define dllclass_api __declspec (dllex) means exporting header files in the test and using the DLL project are used #define dllclass_api __declspec (dllimport) indicating import
3. Regardless of how the header of the DLL project is implemented (for example, including inner functions, etc.), all of the header files in the test and use of the DLL are not defined (the implementation part of the class member function is removed)
4. In the file that tests and uses DLL, it contains the introduction of the DLL library, divided into two steps: first in the TETING menu (by Alt F7 can be called out), in the LINK tab in the process of testing and using the DLL. Object / Library Modules: Fill in the connection to the DLL, such as the DLL file name is DLLClass.lib and dllclass.dll, fill in the release / dllclass.lib (note directory, my program .lib file is under directory Release)
. Then, add a diagram of the header file, such as the DLL file name is DLLClass.lib and dllclass.dll, the header file is DLLClass.h, then the header file is #include "dllclass.h" thereby can be used.
The relevant source code is as follows: DLL project DLLCLASS.H content: // This is DLLEXPORT in the DLL header file, in the application file, DLLIMPIT # define dllclass_api __declspec (DLLEXPORT)
// Export a class (including its method, attribute) class dllclass_api cdllclass {public: cdllclass (void); void msg (const char * const str);
DLLClass.cpp content in the DLL project: #include "stdafx.h" #include "dllclass.h"
BOOL APIENTRY DllMain (HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {switch (ul_reason_for_call) {case DLL_PROCESS_ATTACH: case DLL_THREAD_ATTACH: case DLL_THREAD_DETACH: case DLL_PROCESS_DETACH: break;} return TRUE;}
CDLLCLASS :: cdllclass () {return;} void cdllclass :: msg (const char * const str) {messagebox (null, str, ", mb_ok);} DLL test engineering Dllclass.h content: // here In the DLL's header file, a class (including its method, attribute) (including its method, attribute) Class DLLCLASS_API CDLLCLASS DLLCLASS_API CDLLCLASS {PUBLIC: CDLLCLASS (VOID); Void MSG (Const Char) * const str);}; DLL test engineering DLLCLASSTEST.CPP content: The head: #include "dllclass.h" Class DLLClass;
Code section: cdllclass ctest; ctest.msg ("this is a string inTo DLL");