CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 9 of 9

Thread: Instantianting different copies of a class where there is a static function in it?

Threaded View

  1. #1
    Join Date
    Dec 2010

    Instantianting different copies of a class where there is a static function in it?

    In the code snippet below,
    You can see that the Hook function must be static if I want to assign the function pointer
    to newStruct->pNewFunc, as a consequence, all new'ed copies of newStruct point
    to the same function address. I don't really want that, I want each copy of
    newStruct->pNewFunc to point to a different address, how can I make it happen?

    // This class is exported from the ThreadSpy.dll
    typedef struct
    	char		szDLLName[MAX_PATH];	// The DLL name
    	char		szFuncName[MAX_PATH];	// The function name
    	void *		pNewFunc;				// The new function pointer
    	void *		pPrevFunc;				// The previous function pointer	 	 
    	Flags		flags;					// The flags (hooked or not, etc...)
    	DWORD       iat;                    // The Address of the import table
    } HookStruct;
    class Hookerr
    	Hookerr(std::string _module, std::string _api, DWORD _originalFunc)		 
    		module = _module;
    		api = _api;
    		orignalFunc = (void*)_originalFunc;
    	static std::string module;
    	static std::string api;
    	static void* orignalFunc;
    	//BOOL WINAPI Hook(int n_args, ...);
    	static void Hook(void);
    newHooker.reset(new Hookerr(fullPath, api, mp.first.addr));
    strcpy(newStruct->szDLLName, fullPath.c_str());
    strcpy(newStruct->szFuncName, mp.second.c_str());
    newStruct->pPrevFunc = (void*)mp.first.addr; 
    newStruct->flags = NotHookedYet;
    newStruct->pNewFunc = &newHooker->Hook;
    Last edited by lucky6969b; August 5th, 2016 at 11:23 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)