Sunday, January 24, 2010

Export C++ Classes From a DLL (Windows)



1) Software Using:

Microsoft Windows Vista
Microsoft Visual Studio 2008 (VS9)

2) Create helper macros (Api.hpp):


#ifndef API_HPP
#define API_HPP

#ifdef BUILD_DLL
#define MY_API __declspec(dllexport)
#else
#define MY_API __declspec(dllimport)
#endif /* BUILD_DLL */

#endif /* API_HPP */


3) Define BUILD_DLL in DLL project:





4) Mark DLL classes with MY_API:

#include "Api.hpp"

class MY_API MyClass { ... };



%%

No comments: