VS2010 如何调用 汇编写的dll库

来源:互联网 发布:ug编程和pm编程那个累 编辑:程序博客网 时间:2024/06/04 21:03

首先是编辑dll库

汇编码:

;#########################################################################;Assembler directives.486.model flat,stdcalloption casemap:none;#########################################################################;Include fileinclude AAA.inc.const szTitle db'爱静',0.code;#########################################################################;Common AddIn ProceduresDllEntry proc hInst, reason, reserved1mov eax, 1retDllEntry Endp; Export this proc (it is autoexported if MakeDef is enabled with option 2)InstallDll proc uses ebx hWin:DWORD, fOpt:DWORDmoveax, 1ret InstallDll Endp; Export this proc (it is autoexported if MakeDef is enabled with option 2)_addsproc a,bleaeax,szTitleret_addsendp;#########################################################################End DllEntry
只定义了一个简单的函数 adds 接受2个参数返回一个字符串指针(指针内存的就是内存地址的位置而已) 关于这点可以看C++反汇编与逆向分析技术揭秘

def 文件

EXPORTS _adds
上面的步骤就是生成普通的dll库

接下来写C语言部分:

头文件中定义: 注意这部分只能在头文件中定义

#ifdef __cplusplusextern "C" {#endifchar * __stdcall _adds(int i,int b); #ifdef __cplusplus}#endif
这里看到我们将 4字节的DWORD 当做int  和放在eax中的 "爱静" 字符串的首地址当做char*;这点不明白的可以看C++反汇编与逆向分析技术揭秘,

接下来就需要向项目中添加 刚才汇编生成的lib文件了  

选择lib文件 ,让后就可以了..

当然要运行的程序下必须含有 DLL文件..看好了是汇编生成的DLL文件 而不是lib文件

文件结构如下



VS 真是强大的编辑器= =window下最好的木有之一.