C++ 函数指针引用

C++ 函数指针引用,c++,pointers,C++,Pointers,我需要挂接10/20函数,如下所示: static void* __cdecl HookSoundFileSubBZR(char *FileName, int a2, int a3, int a4); __declspec(naked) void HookSoundFileSub_BZCC_Asm(char *Src, int pedx, int a3, int a4, int a5, int a6); static BOOL HookSoundFile

我需要挂接10/20函数,如下所示:

static void* __cdecl HookSoundFileSubBZR(char *FileName, int a2, int a3, int a4);


 __declspec(naked)  void HookSoundFileSub_BZCC_Asm(char  *Src, int pedx, int 
    
    a3, int a4, int a5, int a6);
    
 static BOOL HookSoundFileSubWCP(int a1, DWORD *a2, DWORD *a3, int a4, char a5, int a6);
我使用这个代码:

switch (int iD)
{
case 1

    DetourAttach(&(LPVOID&)AddressOfHook, &HookSoundFileSubBZR);

case 2
   DetourAttach(&(LPVOID&)AddressOfHook, &HookSoundFileSub_BZCC_Asm);

case 3
   DetourAttach(&(LPVOID&)AddressOfHook, &HookSoundFileSubWCP);
.....
}
但我不想重复x次“DetourAttach”,我喜欢这样做:

switch (int iD)
{
case 1

    HookFunction = &HookSoundFileSubBZR;

case 2
    HookFunction = &HookSoundFileSub_BZCC_Asm;

case 3
   HookFunction = &HookSoundFileSubWCP;
.....
}

DetourAttach(&(LPVOID&)AddressOfHook, &HookFunction);
我问是否有一个简单的方法来做到这一点,因为它更灵活

谢谢

在此更新迂回参数:

LONG WINAPI DetourAttach(_Inout_ PVOID *ppPointer,
                         _In_ PVOID pDetour);
申报

PVOID HookFunction;
然后

HookFunction = (PVOID)HookSoundFileSubBZR;

等等(但是你想在
DetourAttach
调用中使用
HookFunction
),而不是
&HookFunction

听起来有点神秘,在我看来,这似乎是一个XY问题。你想要实现什么?这看起来有点像手工实现vtable:-)我解释得更好,我需要钩住10/20函数,如果可能的话,我希望避免写10/20次“DetourAttach”和“DetourDetach”。DetourAttach(type_1 arg_1,type_2 arg_2){……}的函数定义是什么。给出这个,它可以被当作一个类的构造器。谢谢YTLU,老实说,我没有太多的C++经验,你能举个例子吗?我已经更新了问题。邮政编码。上面的伪代码不是很有启发性。