通过 _declspec(dllexport)可以调用DLL中的类,下面是一个简单的例子。
class simple in test.dll
//simple.h
class _declspec(dllexport) simple
{
public:
simple();
void Set(float x, float y) { _x = x; _y = y;}
float Get() { return _x + _y;}
private:
float _x, _y;
};
in caller class
//caller.cpp
#include "simple.h"
#pragma comment(lib, "test.lib")
class _declspec(dllexport)simple;
int main(int argc, char* argv[])
{
simple s;
s.Set(1,1);
float v = s.Get();
return 0;
}
class simple in test.dll
//simple.h
class _declspec(dllexport) simple
{
public:
simple();
void Set(float x, float y) { _x = x; _y = y;}
float Get() { return _x + _y;}
private:
float _x, _y;
};
in caller class
//caller.cpp
#include "simple.h"
#pragma comment(lib, "test.lib")
class _declspec(dllexport)simple;
int main(int argc, char* argv[])
{
simple s;
s.Set(1,1);
float v = s.Get();
return 0;
}