J
Ganz grob gesagt: Es gibt keine Performante Lösung, wie man auf die Adresse des Aufrufen den kommt. Das einfachste wäre noch Assembler, dann ist es aber nicht mehr portabel.
Du kannst natürlich auch StackWalk64 verwenden, dies ist aber nicht performant:
http://www.codeproject.com/threads/StackWalker.asp
Du kannst auch folgendes machen:
#include <windows.h>
#include <tchar.h>
void __stdcall MyRealFunc(LPCVOID pCallerAddr)
{
MEMORY_BASIC_INFORMATION mbi;
_tprintf(_T("Called from 0x%p\n"), pCallerAddr);
if (VirtualQuery(pCallerAddr, &mbi, sizeof(mbi)) != 0)
{
_tprintf(_T("Module-Base 0x%p\n"), mbi.AllocationBase);
TCHAR szMod[_MAX_PATH];
if (GetModuleFileName((HMODULE) mbi.AllocationBase, szMod, _MAX_PATH) != 0)
_tprintf(_T("Module: %s\n"), szMod);
}
}
__declspec(naked) void MyFunc()
{
__asm push ebp
__asm mov ebp,esp
__asm mov eax, [esp+4]
__asm push eax
__asm call MyRealFunc
__asm mov esp,ebp
__asm pop ebp
__asm xor eax,eax
__asm ret
}
int _tmain()
{
MyFunc();
}