您如何从内联汇编器调用Win32 API函数? [英] How do you call Win32 API functions from inline assembler?

查看:159
本文介绍了您如何从内联汇编器调用Win32 API函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我这段代码有什么问题吗 我只是从kernel32.dll调用Sleep函数 怎么了? 我正在使用Visual Studio 2008. 任何帮助将不胜感激. 非常感谢.

Would somebody please tell me whats wrong with this code I am just calling a Sleep function from the kernel32.dll What's wrong? I am using Visual Studio 2008. Any help would be grateful. Thank you very much.

__asm
{
    mov eax, 77e2ef66h
    push 9999
    call eax
}

推荐答案

77e2ef66h是从哪里获得的那个魔术数字?通常,如果要从内联汇编器调用Win32 API函数,则会执行以下操作:

Where did you get that magic number, 77e2ef66h? Usually if you're calling Win32 API functions from inline assembler, you'd do something like:

__asm 
{ 
    push 9999 
    call Sleep
} 

Win32中的函数没有固定的地址(无论"DLL Export Viewer"可能显示什么).在加载时(通过Windows PE加载程序),功能通过名称 ordinal 链接,并且不在固定地址上.实际上,函数的实际地址可以在Windows版本之间,同一Windows版本中的子版本之间,在计算机之间,甚至在程序的一次运行之间进行更改.

Functions in Win32 do not have a fixed address (regardless of what your "DLL Export Viewer" might show). Functions are linked by name or ordinal at load time (by the Windows PE loader) and are not located at fixed addresses. In fact, the actual address of functions can change between versions of Windows, subreleases within the same version of Windows, from machine to machine, and even possibly from one run of your program to the next.

(免责声明:自从我这样做已经很长时间了,因此上面代码示例的细节无疑是错误的,但是我知道你绝对不需要使用幻数.)

(Disclaimer: It's been a very long time since I've done this, so the details of the above code example are undoubtedly wrong, but I know that you definitely don't need to use magic numbers.)

这篇关于您如何从内联汇编器调用Win32 API函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆