关于exe调用dll的问题,高手请进来告诉我,超级感谢了!

ccccj 2008-06-16 09:35:48
这个是动态连接库源文件
Export.dll的源文件
#include "stdafx.h"

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch(ul_reason_for_call)
{
//DLL被加载到内存时
case DLL_PROCESS_ATTACH:
{
//........其他功能代码
break;
}
//进程中有线程创建时
case DLL_THREAD_ATTACH:
{
//........其他功能代码
break;
}
//线程正常退出时
case DLL_THREAD_DETACH:
{
//........其他功能代码
break;
}
//动态链接库被卸载时
case DLL_PROCESS_DETACH:
{
//........其他功能代码
break;
}
default:break;
}
return TRUE;
}

int MyMessageBox(char *lpText,char *lpCaption)//定义一个整型函数
{
MessageBox(NULL,lpText,lpCaption,0);
return 0;
}
当然加个DEF文件内容
EXPORTS
MyMessageBox//定义为外部函数

///////////////////////////////////////////////////////////////////////
调用这Export.dll时候在improt.exe程序中要定义原型,请看下面这个定义代表什么意思啊有*****表示的那句,感觉这个定义的是这个函数的指针变量啊
improt.exe源文件
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
typedef int(*MyMessageBox)(char *lpText,char *lpCaption);//定义函数原型*****为什么这样定义?DLL中不一样
int main(int argc, char* argv[])
{
//装载DLL文件
HMODULE hModule=LoadLibrary("Export.dll");
if(hModule==NULL)
{
printf("LoadLibrary error \n");
return 0;
}
//得到MyMessageBox地址
MyMessageBox NewMessageBox=(MyMessageBox)GetProcAddress(hModule,"MyMessageBox");
if(NewMessageBox==NULL)
{
printf("GetProcAddress error \n");
return 0;
}
//调用导出函数
NewMessageBox("by 认真的雪","http://www.nohack.cn");
//释放DLL类库
FreeLibrary(hModule);

return 0;
}
希望告诉告诉我??
...全文
108 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sdfssdfgflss 2008-06-16
  • 打赏
  • 举报
回复
guanzhu
heguodong 2008-06-16
  • 打赏
  • 举报
回复
typedef int(*MyMessageBox)(char *lpText,char *lpCaption);//定义函数原型

不是定义函数原型,兄弟
是定义了一个函数指针类型,该指针指向的是一个符合int (char *,char *)标准的函数

调用MyMessageBox NewMessageBox=(MyMessageBox)GetProcAddress(hModule,"MyMessageBox"); 以后
NewMessageBox就指向DLL中的那个MyMessageBox函数
调用NewMessageBox就是调用MyMessageBox



15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧