[Unmanaged] C++ static linking

Oct 1, 2010 at 10:58 PM

Hey there,

I was wondering if there is a possibility to embed the EasyHook functionality in my C++ project. I would like to distribute my DLL using EasyHook as a standalone file. Linking with EasyHook32.lib doesn't seem to do the job, everytime my DLL is loaded it says it can't find the EasyHook32.dll file. Thanks in advance.

Oct 2, 2010 at 3:10 PM

Did you change the EasyHookDll -> Properties -> "Configuration Properties" -> "Configuration Type" to "Static Library (.lib)"?

Oct 2, 2010 at 3:21 PM

Hey thx for your reply... Ye i did actually, it didn't help. The message remains the same.

Oct 2, 2010 at 7:59 PM
Edited Oct 2, 2010 at 8:01 PM

Check out easyhook.h lines 52ff. It will define the functions as "dllexport" if EASYHOOK_EXPORTS is defined. You need to change the preprocessor directives to:


- add DRIVER

Then the macro EASYHOOK_API will be defined as __stdcall and it will compile as a static library.

In your program, define DRIVER as well, so the include file will work correct. I havent checked it, but it should work then. Check out the following link: http://stackoverflow.com/questions/991842/how-to-link-a-static-library-in-visual-c-2008

Oct 20, 2010 at 8:27 PM
Edited Oct 20, 2010 at 8:31 PM

thanks for these pointers, but up until now I did not succeed using these pointers.

First according your hints I changed EasyHookDll->Properties->Configuration Properties->Configuration Type to "Static Library (.lib)".

As I do not have the ntddk.h on my machine I have to avoid setting DRIVER. So within EasyHook.h I changed the definition of the two macros EASYHOOK_API and DRIVER_SHARED_API to the values from the last #ifdef part like

    #define EASYHOOK_API                    __stdcall
    #define DRIVER_SHARED_API(type, decl)   typedef type EASYHOOK_API PROC_##decl; EXTERN_C type EASYHOOK_API decl

In addition I added the following library dependencies to the EasyHookDll project: Aux_ulib_x86.lib;GS_x86.lib;psapi.lib, so these libs are already bundled within the resulting EasyHookDll.lib

As there is some initialization stuff done within DllMain I copied DllMain to my own sources, and added the following external statements to get access to some called functions:

extern "C" void __stdcall LhCriticalInitialize();
extern "C" void __stdcall DbgCriticalInitialize();
extern "C" void __stdcall LhBarrierProcessAttach();
extern "C" void __stdcall LhCriticalFinalize();
extern "C" void __stdcall LhModuleInfoFinalize();
extern "C" void __stdcall LhBarrierProcessDetach();
extern "C" void __stdcall DbgCriticalFinalize();

Now I was able to compile and link successfuly. However, starting my application now takes much longer than before, but I have no idea why? Any more hints? Any description of a real successful static linking against EasyHook.lib?