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

Statically linking to EasyHook

By , 22 Oct 2012
 

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

BOOL APIENTRY 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
Member
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

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
NewsApplication crash when calling LhUninstallAllHooks()memberElmue13 Nov '12 - 17:38 
GeneralRe: Application crash when calling LhUninstallAllHooks()memberJerry.Wang13 Nov '12 - 17:47 
QuestionStrangememberElmue6 Nov '12 - 11:17 
AnswerRe: StrangememberJerry.Wang6 Nov '12 - 13:02 
GeneralRe: StrangememberElmue8 Nov '12 - 2:17 
GeneralRe: StrangememberJerry.Wang8 Nov '12 - 2:53 

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130516.1 | Last Updated 22 Oct 2012
Article Copyright 2012 by Jerry.Wang
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid