调用句柄还可以用HMODULE类来进行调用,代码如下:
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<Windows.h> 4 5 typedef int(*lpAddFun)(int, int); 6 typedef void(*AESFUN)(unsigned char *pskey, unsigned char *blk); 7 unsigned char dll_key_fob[16] = { 0x56, 0x38, 0x97, 0x3f, 0x56, 0x70, 0x22, 0x88, 0x3b, 0x52, 0xfe, 0x5a, 0x01, 0x32, 0x08, 0x49 }; 8 unsigned char buf0[16] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0, 0, 0, 0 }; 9 int main(int argc, char **argv) 10 { 11 unsigned int i; 12 HINSTANCE hDll; 13 lpAddFun addFun; 14 HMODULE hmdl; 15 16 hmdl = ::LoadLibrary(TEXT("..\\AES_Dll.dll")); 17 if (hmdl) 18 { 19 AESFUN newAes = (AESFUN)::GetProcAddress(hmdl, "AesEncrypt"); 20 newAes(dll_key_fob, buf0); 21 for (i = 0; i<16; i++) 22 { 23 if (buf0[i]<0x10) 24 printf("0%X ", buf0[i]); 25 else 26 printf("%X ", buf0[i]); 27 } 28 printf("\n"); 29 } 30 else 31 { 32 printf("Can‘t load dll by hmdl."); 33 } 34 hDll = LoadLibrary(TEXT("..\\WinDll.dll")); 35 if (!hDll) 36 { 37 printf("Can‘t load dll by hdll."); 38 } 39 else 40 { 41 addFun = (lpAddFun)GetProcAddress(hDll, "add"); 42 if (addFun != NULL) 43 { 44 printf("hdll‘s result=%d\n", addFun(1, 2)); 45 } 46 FreeLibrary(hDll); 47 } 48 system("pause"); 49 }
谢谢。
原文地址:https://www.cnblogs.com/lumao1122-Milolu/p/11675302.html
时间: 2024-11-07 10:09:30