I'm learning how to detour-hook functions from tutorials online but when I follow along, my DLL says symbols not found.

The error I get says:

Linking dynamic library: bin\Debug\GLHook.dll
Cannot export GLHook_glAccum: symbol not defined
Cannot export GLHook_glAlphaFunc: symbol not defined

I don't know why though.. I've defined everything :S I'm trying to learn to use definition files while doing this as well.

I have:

MyDetour.h:

typedef void (WINAPI *ptr_glAccum) (GLenum op, GLfloat value);
typedef void (WINAPI *ptr_glAlphaFunc) (GLenum func, GLclampf ref);
extern ptr_glAccum                   optr_glAccum;
extern ptr_glAlphaFunc               optr_glAlphaFunc;

MyDetour.cpp:

ptr_glAccum                   optr_glAccum;
ptr_glAlphaFunc               optr_glAlphaFunc;

void GLHook_glAccum(GLenum op, GLfloat value)
{
    (*optr_glAccum) (op, value);
}

void GLHook_glAlphaFunc(GLenum func, GLclampf ref)
{
    (*optr_glAlphaFunc) (func, ref);
}

MyDetour.def:

LIBRARY GLHook
EXPORTS

glAccum      =    GLHook_glAccum @1
glAlphaFunc  =    GLHook_glAlphaFunc @2

Main.cpp:

#include "main.h"
#include "GLHook.hpp"

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    //........ LoadLibrary("OpenGL32.dll");
    //........ optr_glAccum = GetProcAddress...
}

Main.h:

#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

//void DLL_EXPORT SomeFunction(const LPCSTR sometext);

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__

Any idea why it won't export?

Recommended Answers

All 2 Replies

Your two functions in MyDetour.cpp must be declared with extern "C", and you should probably also add __stdcall since that's the calling convention for OpenGL functions on DLLs (and essentially every other DLL that exists too).

commented: Perfect! It works now :) +5

I got it working but I'm still confused on where to put the __stdcall

I see some tutorials have it as:

Foo __stdcall (Parameters P);

and others have:

Foo(Parameters P); __stdcall //or __attribute__((stdcall))

Now I'm not sure which is correct or what the difference is between the __stdcall and the __attribute version. But why do some put it before and some put it after?
I looked up WINAPI and it's defined as __stdcall.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.