我直接把工程和dll文件打包发上来吧,麻烦各位win7 x86的朋友帮忙测试一下。
WIN7 X32平台 VC++ 6.0
abc.dll 和def.dll是拷自win7 x86 system32目录下的user32.dll文件改名的。
我单步看过了,打印的地址和模块地址都是有效的。
怕大家懒得看 我直接在把整个测试代码发一遍在下面。
#include <windows.h>
#include <stdio.h>
#include <conio.h>
typedef int (CALLBACK *PMessageBoxA)(HWND hWnd,LPCSTR lpText,LPCSTR lpCaption,UINT uType);
typedef int (*PADD)(int x,int y);
void main()
{
HMODULE hLib1,hLib2;
PMessageBoxA func1,func2;
hLib1 = LoadLibraryA("def.dll");
printf("Last Error= %d!\n",GetLastError());
func1 = (PMessageBoxA)GetProcAddress(hLib1,"MessageBoxA");
printf("Last Error= %d!\n",GetLastError());
if (func1!=NULL)
{
func1(NULL,"Hello","Lib1",MB_OK);
printf("Last Error= %d!\n",GetLastError());
}
hLib2 = LoadLibraryA("abc.dll");
printf("Last Error= %d!\n",GetLastError());
func2 = (PMessageBoxA)GetProcAddress(hLib2,"MessageBoxA");
if (func2!=NULL)
{
func2(NULL,"Word","Lib2",MB_OK);
printf("Last Error= %d!\n",GetLastError());
}
printf("hLib1 = 0x%08X,func1 = 0x%08X\nhLib2 = 0x%08X,func2 = 0x%08X\n",hLib1,func1,hLib2,func2);
_getch();
FreeLibrary(hLib1);
FreeLibrary(hLib2);
hLib1 = LoadLibrary("DllDemo1.dll");
hLib2 = LoadLibrary("DllDemo2.dll");
PADD func3,func4;
func3 = (PADD)GetProcAddress(hLib1,"add");
func4 = (PADD)GetProcAddress(hLib2,"add");
func3(10,30);
func4(10,100);
printf("hLib1 = 0x%08X,func3 = 0x%08X\nhLib2 = 0x%08X,func4 = 0x%08X\n",hLib1,func3,hLib2,func4);
FreeLibrary(hLib1);
FreeLibrary(hLib2);
}
下面是附件工程:
testLoadDll.zip