码迷,mamicode.com
首页 > 其他好文 > 详细

vs2013 调用只有dll文件的动态库(二)

时间:2019-10-15 09:33:09      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:signed   lib   module   vs2013   句柄   def   unsigned   include   文件的   

调用句柄还可以用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 }

谢谢。

vs2013 调用只有dll文件的动态库(二)

标签:signed   lib   module   vs2013   句柄   def   unsigned   include   文件的   

原文地址:https://www.cnblogs.com/lumao1122-Milolu/p/11675302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!