Home > OS >  Will generate DLL dynamic link library class C
Will generate DLL dynamic link library class C

Time:11-20

Environment: VS2010
The MyClass class, for example, to create a DLL project, create. H file and. CPP file, I am here to MyClass. H, MyClass. CPP, for example,
Myclass. H file
MyClass class _declspec (dllexport)
{
Public:
Void the show ();
};

Myclass. CPP file: the realization of a class member function

Void MyClass: : show ()
{
Cout<& lt;" Custom class MyClass "& lt; }

Generate DLL files and.lib file (toolbar - "generation --" generate solutions), at this point, in your project folder below the debug folder will see the generated DLL file with the.lib file,


DLL with implicit call:

Create a console application, you can set up an empty project, add. H file and. CPP file, I am here to test. The h and test. The CPP, for example,
Added for engineering test. H and test. After the CPP, compiled the first, the debug file (note to write the main () function)

The DLL project generated DLL and the lib files are added to the test project, specific methods are as follows:

Add you generate DLL to the debug directory (yes. Exe file directory), the lib files are added to the engineering (engineering file right click - "add -" existing items - "find your.lib file -" add),. H file also need to add to the program running directory (not the debug directory, is your project directory where h file with the CPP files), but. H file needs to be done to modify, will
Class _declspec (dllexport) instead of MyClass class _declspec (dllimport) MyClass

Test. H file:

# # ifndef _TEST_H__
# define _TEST_H__

Here include the header file
#include
Here need to include # include "myclass. H"

using namespace std;

# endif

The test, the CPP file:

Contains the test. H "# include"

Int main (int arg c, char * argv [])
{
Here you can use the MyClass class
MyClass MC.
MC. The show ();
getchar();
return 0;
}


Note: DLL, lib files,. H file to add is very important, can't put the wrong position,. H file must do change
  • Related