Link to OpenGL32.dll

Ok, I know I shouldn’t post this message here, but here it goes…

I’m programming in VS6 and I have created a project here I’ve included all my .cpp and .h. If I would use OpenGL in one of the .cpp or .h I would include “gl/gl.h”. Of course the project was linked with the opengl32.lib. But this way I can’t link to whatever dll I want… So…

I’ve created two files: “OpenGL.cpp” and “OpenGL.h”:

=>In “OpenGL.h” I have included:
typedef unsigned int GLenum;
typedef unsigned char GLboolean;

#define GL_VERSION_1_1 1
#define GL_ACCUM 0x0100

=>created the prototypes:
typedef void (WINAPI* pfnglAccum) (GLenum op, GLfloat value);
typedef void (WINAPI* pfnglAlphaFunc) (GLenum func, GLclampf ref);

=>and the functions pointers:
#ifdef __cplusplus
extern “C” {
#endif
extern pfnglAccum glAccum;
extern pfnglAlphaFunc glAlphaFunc;

#ifdef __cplusplus
}
#endif
=>and two functions to load and unload everything:
bool OpenGL_Load(char *pszDllName);
bool OpenGL_Unload(void);

and replaced the “#include gl/gl.h” in every file I use with “OpenGL.h”, and took of “opengl32.lib”. My “OpenGL.cpp” file looks like this:

#include <windows.h>
#include “OpenGL.h”

static HMODULE OpenGL_DLL=NULL;

pfnglAccum glAccum;
pfnglAlphaFunc glAlphaFunc;

#define GETADDR(type, var, name) var = (type)GetProcAddress(OpenGL_DLL, name)

static void SetProcs(void)
{
GETADDR(pfnglAccum,glAccum,“glAccum”);
GETADDR(pfnglAlphaFunc,glAlphaFunc,“glAlphaFunc”);

}

bool OpenGL_Load(char *pszDllName)
{
if (OpenGL_DLL!=NULL) return false;

OpenGL_DLL=LoadLibrary(pszDllName);
if (OpenGL_DLL==NULL) return false;

SetProcs();
return true;

}

bool OpenGL_Unload(void)
{
if (OpenGL_DLL==NULL) return false;

FreeLibrary(OpenGL_DLL);
OpenGL_DLL=NULL;
return true;

}

Now everything compiles and links correctly…but when I run the .exe:
“The instruction at “0x00000000” referenced memory at “0x00000000”. …”
when I debug it it even doesn’t enter WinMain…

You see my dilema… What am I doing wrong?
And should I replace the default OpenGL32.dll by one that suports 1.2?
Thanks for any help…

I have a question. What exactly are you trying to accomplish in this code? It isn’t exactly obvious what you intend to accomplish.

something went wrong, and you just need to debug it. This code seems fine, but compilers are weird.

  1. Do RebuildAll. When you do big changes, some things may go wrong if you just do build because VC++ reuses all the obj files it can.
  2. If this doesn’t work, then you’ll have to go to manual debug

Comment out all the fonction bodies in opengl.cpp and check if the program can at least go to main. If it does, then uncomment function by function until you find what is wrong. You might even find that the problem is not from the .cpp.

If it doesn`t, then post the whole source code somewhere and I will have a look at it. But of course, most likely, the problem is from your changes.

But most likely the problems

[This message has been edited by Gorg (edited 05-24-2001).]

What I’m trying to do is to not link to the default “opengl32.dll”… I want to do dinamically linking…

As for the debug… I can’t debug it… It crashes even before entering the main… It’s impossible to debug… And yes I have rebuild ALL… even erased the Debug folder with all of the files… I still can’t make out what is wrong and I will try to post the code somewhere…

Originally posted by KRONOS:
[b]What I’m trying to do is to not link to the default “opengl32.dll”… I want to do dinamically linking…

As for the debug… I can’t debug it… It crashes even before entering the main… It’s impossible to debug… And yes I have rebuild ALL… even erased the Debug folder with all of the files… I still can’t make out what is wrong and I will try to post the code somewhere…[/b]

Did you try to comment out code? Anyway just post it somewhere.

your SetProcs is terrible dangerous, isn’t it? you dont check any functionpointer if it does exist or if it doesn’t, do you?

check every functionpointer if it is valid or zero at SetProcs and return true if every pointer is correct…

oh, and you need the wglCreateContext functions and all those, they are somewhere in the dll, too… else you cant initialize opengl ( simply if you call some opengl function without creating it, sometimes we forget the simplest, me included… )

OK… guys… forget the code… The compiler and linker build a program that doen’t even start!!! SetProc should be better but that is not the point… It doesn’t even enter WinMain… so how can I call SetProc!!!

Just email me the code!

This kind of problems happens to everyone at least one time in it’s life and It is fixable.