Click here to Skip to main content
15,881,600 members
Articles / Desktop Programming / Win32

Generic Thunk with 5 combinations of Calling Conventions

Rate me:
Please Sign up or sign in to vote.
2.78/5 (8 votes)
13 Apr 2008CPOL12 min read 33.3K   398   19  
A simple and generic solution of making a member function become a callback function with the help of thunk technology.
#include <Thunk/ThisToCdecl.h>
//#include <assert.h>

#define THUNK_MACHINE_CODE_IMPLEMENT
#include <Thunk/MachineCodeMacro.h>

namespace Thunk
{
	ThisToCdecl::~ThisToCdecl()
	{}

	ThisToCdecl::ThisToCdecl(const void *Obj,int memFunc)
		__THIS_TO__CDECL_CODES()
	{
		Helper::SetTransferDST(&CALL,memFunc);
	}

	dword_ptr ThisToCdecl::Attach(dword_ptr newObj)
	{
		dword_ptr oldObj = m_this;
		m_this = newObj;
		return oldObj;
	}

	dword ThisToCdecl::Attach(dword newFunc)
	{
		dword oldFunc = Helper::GetTransferDST(&CALL);
		Helper::SetTransferDST(&CALL,newFunc);
		return oldFunc;
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Junior)
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions