vs64位程序不支持__asm内嵌汇编,需要单独编写汇编源文件
示例如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <Windows.h>
extern "C" void __stdcall asm_func(const char* lpText);
extern "C" UINT GetMsgBoxType() { return MB_YESNOCANCEL; }
int main() { asm_func("Hello world!"); return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
.data
msgCaption db 'Message box text',0
.code align 16
extern GetMsgBoxType : proc extern MessageBoxA : proc extern __imp_MessageBoxA : qword
asm_func proc ; RCX = address for the string for the message box sub rsp, 28h ; shadow stack only [n]8 size
lea rdx, [msgCaption] mov r8, rcx
call GetMsgBoxType mov r9, rax xor rcx, rcx
;call [__imp_MessageBoxA] call MessageBoxA
add rsp, 28h ; restoring shadow stack ret asm_func endp
end |
3.1 右键项目 --> 生成依赖项 --> 生成自定义 --> 勾选masm
3.2 右键汇编源文件 --> 属性 --> 常规 --> 项类型 --> Microsoft Macro Assembier