• vc 导出函数/调用


    loader(exe):

    #include "stdafx.h"
    #include <Windows.h>
    #include <stdio.h>
    #define Loaddll_API __declspec(dllexport)
    extern "C" Loaddll_API int _stdcall testloader(void);
    #pragma comment(lib,"Loaddll")
    int main(int argc,char* argv[])
    {
        testloader(); //隐式调用
    
        //显示调用
        typedef  int(_stdcall *Fun)(void);
        HMODULE hmod = LoadLibraryA("Loaddll.dll");
        Fun testFun = GetProcAddress(hmod,"testloader");
        testFun();
    
    
        system("pause");
        return 0;
    }

    dll:Loaddll

    #include "stdafx.h"
    #include <Windows.h>
    #include <stdio.h>
    #define Loaddll_API __declspec(dllexport)
    extern "C"  Loaddll_API int _stdcall testloader(void);
    BOOL APIENTRY DllMain( HMODULE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID 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;
    }
    
    extern "C" int _stdcall testloader(void)
    {
        MessageBoxA(NULL,"loader dll","Title",MB_OK);
        printf("Hello word,this is a export dll functions
    ");
        return 0;
    }

    添加一个.def模块定义文件。

    LIBRARY "Loaddll"
    
    EXPORTS
    
    testloader @ 1

  • 相关阅读:
    NopCommerce4.2 常见错误及异常处理
    使用NopCommerce微信电商系统
    简单理解Socket
    html5 postMessage解决跨域、跨窗口消息传递
    html5 Web Workers
    node.js module初步理解
    node.js调试
    最简单的JavaScript模板引擎
    简单JavaScript模版引擎优化
    容易被忽略CSS特性
  • 原文地址:https://www.cnblogs.com/killbit/p/5324150.html
Copyright © 2020-2023  润新知