Tri*_*rom 4 c winapi reverse-engineering
简短的问题。
当我做:
#include <windows.h>
CreateProcess(..)
Run Code Online (Sandbox Code Playgroud)
头文件如何知道将我连接到正确的 dll?
这些头文件中是否有一个字典将每个 win32api 函数映射到相关的 dll?
标头仅包含 API 函数的声明,而不包含其定义。通过链接适当的库可以找到定义。
例如,将以下内容复制到.c文件中:
#include <Windows.h>
int main()
{
MessageBoxW(NULL, L"Hello World", L"", MB_OK);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
尝试使用以下命令在 Visual Studio 命令提示符下编译它cl example.c。您将看到错误消息:
example.obj : error LNK2019: unresolved external symbol __imp__MessageBoxW@16 referenced in function _main
Run Code Online (Sandbox Code Playgroud)
请注意,编译本身实际上是成功的;这是链接器抱怨缺少函数定义。
如果您使用 编译它cl example.c /link user32.lib,链接器将找到 的定义MessageBox。你也可以只是link example.obj user32.lib。
因此,回答您的问题:标头不需要知道函数位于哪些 DLL 中,因为项目需要提供适当的库引用。幸运的是,Windows API 函数的 MSDN 文档会告诉您该函数位于哪个 DLL 中以及要链接哪个库。