If your work has long been associated with a field, such as a long-term development of direct volume rendering (DVR), you may often use your own transfer function class, If you add the. h and. cpp files of the transfer function class to each project, you'll be in trouble, in fact, we can use your own class as you would with the OpenGL library, by encapsulating your written class into a DLL, as follows:
The first step: Making DLLs
Using VC6 to create a new project, select the Win32 Dynamic-link Library (Empty project), and then add the header file and CPP file. Suppose you want to encapsulate the class name into Transferfunction, add header Files TransferFunction.h and TransferFunction.cpp to the project. and modify the TransferFunction.h into:
Class __declspec (dllexport) transferfunction
{
...
}
This indicates which class is to be exported from the DLL later. This will result in the TransferFunction.dll and TransferFunction.lib two files being compiled.
Step Two: How to use this DLL
When a DLL has been built, there are two ways to invoke classes and member functions in the DLL in other programs:
method One:
1 copy TransferFunction.dll and TransferFunction.lib to the execution path of the calling program, and note that it is not under the debug path.
2) Add TransferFunction.lib to Project->setting->link (or #pragma comment (lib, "TransferFunction.lib")
3) Convert the __declspec (dllexport) in TransferFunction.h to __declspec (dllimport)
It is then copied to the execution path of the calling program.
4 Finally, the Transferfunction class and its member functions can be used in the main program by including TransferFunction.h.
method Two (recommended):
In method one, every time you build a project you need to put transferfunction.dll,transferfunction.lib, TransferFunction.h three copies of files to the project, in fact, this only plays the DLL to the class code protection function, and not much reduce the programmer's workload, the following method can reduce the workload of programmers, the specific steps:
1: Throw the TransferFunction.dll under the Windows/system32
2: Will. Transferfunctionlib threw it into the VC's lib directory.
3: Throw the TransferFunction.h in the method one into the VC's include directory
4: The last step of the same method one.
You can then use a reusable class of your own encapsulation like the glut, Glui, and other libraries in OpenGL.