Article ID: 107501
Article Last Modified on 4/28/2005
- or -
/* exported function */
__declspec( dllexport ) void func();
/* exported data */
__declspec( dllexport ) int i;
// exported class
class __declspec( dllexport ) DLLClass
{
...
};
class DLLClass
{
public:
// exported member function
__declspec( dllexport ) void MemberFunction( void );
};
The sample code below demonstrates exporting classes and class member
functions from a DLL using the __declspec( dllexport ) and __declspec(
dllimport ) storage class attributes in the DLL and EXE, respectively.
/* DLL Sample: TESTDLL.CPP
/* Compile options needed: /D"_X86" /MT TESTDLL.CPP /link
/* /DLL /OUT:testdll.dll /implib:testdll.lib
*/
#include <stdio.h>
class DLLClass
{
public:
// exported member function
__declspec( dllexport ) void functionA( void ) {
printf("\nIn Function A of the exported function");
}
};
// exported class
class __declspec( dllexport) ExportDLLClass
{
public:
void functionB(void) {
printf("\nIn Function B of the exported class");
}
};
// exported instance of the DLLClass
__declspec(dllexport) DLLClass test;
/* Source that calls the DLL Sample: CALLDLL.CPP
/* Compile options needed: /D"_X86" /D"_CONSOLE" /ML CALLDLL.CPP
/* TESTDLL.LIB
*/
#include <stdio.h>
class DLLClass
{
public:
// imported member function
__declspec( dllimport ) void functionA( void );
};
class __declspec( dllimport) ExportDLLClass
{
public:
void functionB(void);
};
__declspec( dllimport ) DLLClass test;
void main(void)
{
ExportDLLClass TestClass;
test.functionA();
TestClass.functionB();
}
__export and def and prolog and dllexport
Additional query words: 8.00 9.00
Keywords: kblangc KB107501