• 生成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?
    ";
        }
        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; }

    运行结果:

  • 相关阅读:
    Use JAWS 14 in a VM
    远程文件拷贝
    MVA Prototype Only User License
    Global.asax 详解
    GridView of different size items
    Windows Phone 8, 添加Map控件
    动态规划——递归写法和递推写法
    守形数
    遍历链表
    成绩排序
  • 原文地址:https://www.cnblogs.com/YLJ666/p/14831287.html
Copyright © 2020-2023  润新知