zoukankan      html  css  js  c++  java
  • Convert console application to dll on Visual Studio

    Go to Project Property Page/Cofniguration Properties

    General/Configuration Type, change as “Dynamic Library(.dll)”

    C/C++/Code Generation/Runtime Library, change as “/MDd”

    C/C++/Preprocessor/Preprocessor Definitions, add macro “YOURDLL_EXPORTS”

    Linker/System/SubSystem, change as “Windows(/Subsystem:windows)”

    Linker/Advanced/Import Library, change as ...$(TargetName).lib

    Create an header contains the export interfaces

    #pragma once
    #ifdef YOURDLL_EXPORTS
    #define YOURDLL_API __declspec(dllexport)
    #else
    #define YOURDLL_API __declspec(dllimport)
    #pragma comment (lib, "YOURDLL.lib")
    #endif

    And then add a dllmain.cpp file contains the allocation and deallocation for this dll
    #include "stdafx.h"
    BOOL APIENTRY DllMain( HMODULE hModule,
    DWORD ul_reason_for_call,
    LPVOID lpReserved
    )
    {
    UNREFERENCED_PARAMETER(hModule);
    UNREFERENCED_PARAMETER(lpReserved);

    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
    break;
    }
    return TRUE;
    }

    YOURDLL_API int Add(int lhs, rhs);
    as the abovev code, the Add function will be explored outside to invoke. If you want to explore an entire class, you should declare a class like this way:
    class YOURDLL_API CTest
    {
    public:
    static int Add(int lhs, rhs);
    };


  • 相关阅读:
    Chunky Monkey(算法)
    Confirm the Ending(算法)
    Return Largest Numbers in Arrays(算法)
    防止SQL注入总结
    mybatis中的#和$的区别 以及 防止sql注入
    拆分字符串为树形结构
    虚拟机类加载机制
    linux加载字体
    项目上线暴露出的问题
    浅析正则表达式-应用篇
  • 原文地址:https://www.cnblogs.com/rogerroddick/p/2963402.html
Copyright © 2011-2022 走看看