如何调用DLL中的类

来源:互联网 发布:淘宝客pid三段什么意思 编辑:程序博客网 时间:2024/06/08 00:16
通过 _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;
}
原创粉丝点击