Win7 VS2015 x64 MASM汇编语言编写DLL文件

有点坑记录一下。

首先创建工程时选控制台类型工程,Win32估计就应该选Win32的,反正我测试用的控制台。

然后选DLL类型,除了Empty其他全都去掉。

工程属性,masm勾上。

 

Linker >> Advanced里

Entry Point写上默认的入口函数

DllEntryPoint

Linker >> Input里

Module Definition File写上你所用的def文件名

建立asm和def文件,如下

 

ASM

 

.code

DllEntryPoint proc
	mov rax, 1
	ret
DllEntryPoint endp

AddFun proc
	mov eax, ecx
	add eax, edx
	ret
AddFun endp
end

 

DEF

 

LIBRARY "ASM64DLLTest"  
EXPORTS  
AddFun

 

 

然后就可以了,只是一个简单的加法函数,对应C++版本为

__declspec(dllexport) int Add(int a, int b)
{
	return (a + b);
}

 

然后写个x64控制台程序测试一下。

 

#include <iostream>

#include <windows.h> 

using namespace std;

typedef int(*MYPROC)(int, int);

int main()
{
	HINSTANCE hinstLib;
	MYPROC ProcAdd;
	BOOL fFreeResult = FALSE;

	// Get a handle to the DLL module.
	hinstLib = LoadLibrary(TEXT("ASM64DLLTest.dll"));

	// If the handle is valid, try to get the function address.
	if (hinstLib != NULL)
	{
		ProcAdd = (MYPROC)GetProcAddress(hinstLib, "AddFun");

		// If the function address is valid, call the function.
		if (NULL != ProcAdd)
		{
			cout << (ProcAdd)(1, 2) << endl;

			cout << "LoadLibrary Success and Function Run" << endl;
		}
		else
		{
			cout << "LoadLibrary Success and GetProcAddress Fail" << endl;
		}

		// Free the DLL module.
		fFreeResult = FreeLibrary(hinstLib);

		if (fFreeResult == 1)
		{
			cout << "FreeLibrary Success" << endl;
		}
		else
		{
			cout << "FreeLibrary Fail" << endl;
		}
		
	}
	else
	{
		cout << "LoadLibrary Fail" << endl;
	}

	return 0;
}

  

结果

 

 

转载于:https://www.cnblogs.com/kileyi/p/7257852.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值