zoukankan      html  css  js  c++  java
  • 生成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; }

    运行结果:

  • 相关阅读:
    需要union
    with语法,需要递归的面试题目
    聚合主分类,子查询获得子分类
    泛型
    RepeaterInMVC
    需要自己创建集合的题目
    Ollydbg入门
    svn服务器架设
    http与svn架设服务器
    svn错误信息一览表
  • 原文地址:https://www.cnblogs.com/YLJ666/p/14831287.html
Copyright © 2011-2022 走看看