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.
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.
EDIT: 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?
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.