#pragma once #include <iostream> using namespace std; namespace MyDLL { //导出类 class MyDLL { public: MyDLL(); ~MyDLL(); int add(int x, int y); //简单方法 } ; extern "C" __declspec(dllexport) void ShowMsg(); }
#include "MyDLL.h" namespace MyDLL { MyDLL::MyDLL() { } MyDLL::~MyDLL() { } extern "C" __declspec(dllexport)void ShowMsg(); void ShowMsg() { cout << "HHDD" << endl; } int MyDLL::add(int x, int y) { return x+y; } }
#include "MyDLL.h" #include <iostream> using namespace std; extern "C" void ShowMsg(); void main() { MyDLL::MyDLL myDll = MyDLL::MyDLL(); int result = myDll.add(1000,2000); ShowMsg(); cout << result << endl; system("pause"); }