关于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;
}
希望告诉告诉我??