VS2010 如何调用 汇编写的dll库

首先是编辑dll库

汇编码:

;#########################################################################
;		Assembler directives

.486
.model flat,stdcall
option casemap:none

;#########################################################################
;		Include file

include AAA.inc

.const 
	szTitle 	db	'爱静',0
.code

;#########################################################################
;		Common AddIn Procedures

DllEntry proc hInst, reason, reserved1	
	mov eax, 1
	ret
DllEntry Endp
; Export this proc (it is autoexported if MakeDef is enabled with option 2)
InstallDll proc uses ebx hWin:DWORD, fOpt:DWORD
	mov	eax, 1
	ret 

InstallDll Endp
; Export this proc (it is autoexported if MakeDef is enabled with option 2)
_adds	proc a,b
	lea	eax,szTitle
	ret
_adds	endp
;#########################################################################
End DllEntry
只定义了一个简单的函数 adds 接受2个参数返回一个字符串指针(指针内存的就是内存地址的位置而已) 关于这点可以看C++反汇编与逆向分析技术揭秘

def 文件

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

接下来写C语言部分:

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

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

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

VS2010 如何调用 汇编写的dll库_第1张图片

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

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

文件结构如下

VS2010 如何调用 汇编写的dll库_第2张图片

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


你可能感兴趣的:(VS2010 如何调用 汇编写的dll库)