vc 导出函数/调用 - 杀死比特
2016-3-26 21:43:0 Author: www.cnblogs.com(查看原文) 阅读量:2 收藏

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\r\n");
    return 0;
}

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

LIBRARY "Loaddll"

EXPORTS

testloader @ 1


文章来源: https://www.cnblogs.com/killbit/p/5324150.html
如有侵权请联系:admin#unsafe.sh