Visual C ++-重写从DLL导入的函数? [英] Visual C++ - overriding a function imported from a DLL?

查看:75
本文介绍了Visual C ++-重写从DLL导入的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试覆盖kernel32.dll中的特定功能。是否可以在静态库中重新定义该功能并强制可执行文件在静态库中使用该功能?我猜想不同的链接可能会成为问题。

I'm trying to override a specific function in kernel32.dll. Is it somehow possible to redefine that function in a static library and force the executable to use the one in the static library? I guess the different linkage could become a problem.

可以使用我自己的自定义DLL覆盖它。但是问题是DLL本身需要链接到kernel32.dll,因此它忽略了我对该函数的定义。

It would be possible to override it with my own custom DLL. However the problem is that the DLL itself needs to link to kernel32.dll, so it ignores my definition of that function.

编辑:我让它与我自己的DLL一起使用。构建它时,需要禁用链接时间代码生成。

I got it working with my own DLL. When building it, link time code generation needs to be disabled. What about linking the overridden function statically though?

推荐答案

是的,这没什么大问题。函数定义为 __ dllimport ,但未指定从哪个DLL导入。链接器仅选择提供它们的第一个导入库。因此,。只需先通过您的图书馆即可。在MSVC中,您需要禁用包含标准库,因为那些自定义库之前。

Yes, this is no big problem. Functions are defined as __dllimport, but that does not specify which DLL they're imported from. The linker simply picks the first import library that provides them. Therefore,. just pass your library first. In MSVC, you'll need to disable "include standard libraries", as those precede custom libraries.

这篇关于Visual C ++-重写从DLL导入的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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