Click here to Skip to main content
Click here to Skip to main content

Statically linking to EasyHook

, 31 Jul 2014
Rate this:
Please Sign up or sign in to vote.
Instructions about linking EasyHook library statically

Easyhook is a powerful open source library from http://easyhook.codeplex.com/.

Compile EasyHook as static library 

To link with EasyHook statically, first open the Properties popup, change the Configuration Type to "Static library (.lib)"   

Then, remove the "EASYHOOK_EXPORTS" preprocesser definition as below.   

Find DllMain, rename it to "EasyHookDllMain

Open easyhook.h,  line 51, find the following code.

#ifdef EASYHOOK_EXPORTS
    #define EASYHOOK_API						__declspec(dllexport) __stdcall
	#define DRIVER_SHARED_API(type, decl)		EXTERN_C type EASYHOOK_API decl
#else
    #ifndef DRIVER
        #define EASYHOOK_API					__declspec(dllimport) __stdcall
		#define DRIVER_SHARED_API(type, decl)	EXTERN_C type EASYHOOK_API decl
    #else
        #define EASYHOOK_API					__stdcall
		#define DRIVER_SHARED_API(type, decl)	typedef type EASYHOOK_API PROC_##decl; EXTERN_C type EASYHOOK_API decl
    #endif
#endif  

Replace them with

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

And now you can compile the library.  

Use the static library  

Open the project which will use the generated static library above. 

Call EasyHookDllMain in your DllMain

EASYHOOK_BOOL_EXPORT EasyHookDllMain( HMODULE hModule,
	DWORD  ul_reason_for_call,
	LPVOID lpReserved
	);


BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	EasyHookDllMain( hModule, ul_reason_for_call, lpReserved);

	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
	return TRUE;

Link the libraries.

#pragma comment( lib, "EasyHook32.lib") // or EasyHook64.lib, depending on your project
#pragma comment( lib, "Aux_ulib.lib")
#pragma comment( lib, "psapi.lib") 

Now try to compile your project, if you get some complication error like

 error LNK2026: module unsafe for SAFESEH image 

 You can try to switch the SAFESEH to NO as bellow 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Jerry.Wang
Team Leader
China China
Jerry is from China. He was captivated by computer programming since 13 years old when first time played with Q-Basic.
 

  • Windows / Linux & C++
  • iOS & Obj-C
  • .Net & C#
  • Flex/Flash & ActionScript
  • PHP / HTML / CSS / Javascript
  • Gaming Server programming / video, audio processing / image & graphics
 
Contact: 32775973(at)qq.com
Chinese Blog: http://blog.csdn.net/wangjia184

Comments and Discussions

 
NewsApplication crash when calling LhUninstallAllHooks() PinmemberElmue13-Nov-12 17:38 
GeneralRe: Application crash when calling LhUninstallAllHooks() PinmemberJerry.Wang13-Nov-12 17:47 
QuestionStrange PinmemberElmue6-Nov-12 11:17 
AnswerRe: Strange PinmemberJerry.Wang6-Nov-12 13:02 
GeneralRe: Strange PinmemberElmue8-Nov-12 2:17 
GeneralRe: Strange PinmemberJerry.Wang8-Nov-12 2:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 31 Jul 2014
Article Copyright 2012 by Jerry.Wang
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid