Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Мультимедия, OpenGL/DirectX > Проблема с хуком Direct X в MinGW.


Автор: CynicRus 14.8.2012, 12:27
Приветствую уважаемых форумчан. Пытаюсь сделать хук на EndScene при помощи apihijack. В ApiHijack.h описаны структуры:

Код

struct SFunctionHook
{
    char* Name;         // Function name, e.g. "DirectInput8Create".
    DWORD* HookFn;       // Address of your function.
    DWORD* OrigFn;       // Stored by HookAPICalls, the address of the original function.
};

struct SDLLHook
{
    // Name of the DLL, e.g. "DDRAW.DLL"
    char* Name;

    // Set true to call the default for all non-hooked functions before they are executed.
    bool UseDefault;
    void* DefaultFn;

    // Function hook array.  Terminated with a NULL Name field.
    SFunctionHook* Functions[];
};


и при попытке использовать данную структуру:
Код

SDLLHook D3DHook =
{
    "DDRAW.DLL",
    false, NULL,
    {
        { "DirectDrawCreateEx", MyDirectDrawCreateEx },
        { NULL, NULL }
    }
};
 я получаю ошибку: error: too many initializers for 'SFunctionHook* [0]'. Собственно - каким образом разрешить данную проблему?

Автор: korian 14.8.2012, 14:34
Цитата(CynicRus @  14.8.2012,  11:27 Найти цитируемый пост)
 я получаю ошибку: error: too many initializers for 'SFunctionHook* [0]'. Собственно - каким образом разрешить данную проблему? 

То что я нашел, выглядет вот так
Код

struct SDLLHook
{
    // Name of the DLL, e.g. "DDRAW.DLL"
    char* Name;
    // Set true to call the default for all non-hooked functions before they are executed.
    bool UseDefault;
    void* DefaultFn;
    // Function hook array.  Terminated with a NULL Name field.
    SFunctionHook Functions[];
};

Что соответствует вот этому:
Код

struct SDLLHook
{
    // Name of the DLL, e.g. "DDRAW.DLL"
    char* Name;
    // Set true to call the default for all non-hooked functions before they are executed.
    bool UseDefault;
    void* DefaultFn;
    // Function hook array.  Terminated with a NULL Name field.
    SFunctionHook Functions[0];
};

Соответственно вы не можете запихать в Functions больше элементов, чем 0.
А использоваться это, по идее, должно вот так:
Код

   int function_count = 2;
   void* mem_ptr = malloc(sizeof(SDLLHook) + sizeof(SFunctionHook) * function_count);
   SDLLHook *D3DHookPtr = (SDLLHook *)mem_ptr;
   D3DHookPtr->Name = "DDRAW.DLL";
   D3DHookPtr->UseDefault = false;
   D3DHookPtr->DefaultFn = NULL;
   D3DHookPtr->Functions[0] = { "DirectDrawCreateEx", MyDirectDrawCreateEx, NULL };
   D3DHookPtr->Functions[1] = { NULL, NULL, NULL };


Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)