生成dll并供外部调用
创建一个空项目即可,更改项目属性:
头文件
#pragma once #define DLL_EXPORT #if defined (DLL_EXPORT) #define GIRLAPI _declspec(dllexport) #else #define GIRLAPI _declspec(dllimport) #endif #include<string> class Girl { public: virtual void getType() = 0; virtual std::string getType(std::string) = 0; }; extern "C" GIRLAPI Girl * createGirl();
源文件
#include"girlBase.h" #include<iostream> class MyGirl :public Girl { public: void getType() { std::cout << "fill up her cunt?\n"; } std::string getType(std::string str) { return str; } }; Girl* createGirl() { MyGirl *girl=new MyGirl; return girl; }
测试文件
#include "../testDll/girlBase.h" #pragma comment(lib,"testDll.lib") #include <iostream> using namespace std; int main() { Girl*girl=createGirl(); girl->getType(); cout<<girl->getType("HOT")<<endl; delete girl;
system("pause"); return 0; }
运行结果: