Exporting Classes
-
Hey Guys I have been trying to export a class from a DLL for ages now and had little luck could someone post a quick example or tutorial on how to export a class. Peter
-
Hey Guys I have been trying to export a class from a DLL for ages now and had little luck could someone post a quick example or tutorial on how to export a class. Peter
This example was generated by the app wizards for a DLL. Here is the header file:
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the EXAMPLE_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// EXAMPLE_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef EXAMPLE_EXPORTS
#define EXAMPLE_API __declspec(dllexport)
#else
#define EXAMPLE_API __declspec(dllimport)
#endif// This class is exported from the example.dll
class EXAMPLE_API CExample {
public:
CExample(void);
// TODO: add your methods here.
};extern EXAMPLE_API int nExample;
EXAMPLE_API int fnExample(void);
Here is the cpp file:
// example.cpp : Defines the entry point for the DLL application.
//#include "stdafx.h"
#include "example.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;
}// This is an example of an exported variable
EXAMPLE_API int nExample=0;// This is an example of an exported function.
EXAMPLE_API int fnExample(void)
{
return 42;
}// This is the constructor of a class that has been exported.
// see example.h for the class definition
CExample::CExample()
{
return;
}Good Luck!
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life! -
Hey Guys I have been trying to export a class from a DLL for ages now and had little luck could someone post a quick example or tutorial on how to export a class. Peter
class AFX_EXT_CLASS CMyClass { ... } Cheers, Tom Archer Author, Inside C# Author, Visual C++.NET Bible A total abstainer is one who abstains from everything but abstention, and especially from inactivity in the af