I noticed that a lot of examples use something like:

FARPROC SomeFunction = (FARPROC)GetProcAddress(LoadLibrary(“SomeLib.DLL”), “SomeFunction”);

And then the proceed to use the function:

SomeFunction(param1, param2, etc);

But whenever I try to do this the compiler returns to me saying that there are too many actual parameters to the function, and that the function is prototyped as SomeFunction(void).

Why is this, and how do I go about doing this the right way?


Do you create a function pointer to use? For instance.

typedef void (*PFNSOMEFUNC)(int x, int y, int z);

PFNSOMEFUNC SomeFunc = (PFNSOMEFUNC)GetProcAddress(LoadLibrary(“SomeLib.dll”), “SomeFunc”);


This has always worked well for me.

[This message has been edited by Deiussum (edited 03-30-2001).]

Thats why I usually do.

But whenever I look at MSDN documentation about various API extensions (not OpenGL - Win32 API), they simply declare a pointer of type FARPROC and then get the address and assign it to that variable. Then, every subsequent call they make includes parameters and there is no prototype for the function.

What am I missing here?


You’ve not seen that at all, liar!
You can only call a function with the parameters declared in it’s prototype.
A function pointer should be of a certain type - that type is one that you create (or include from a header file).

I thought this would be a good post to jump in on. I’m using wglGetProcAddress for the first time in order to use glTexImage3D. I can get the address fine, but then I have another problem. Compiling in VC++6 gives me the error GL_TEXTURE_3D undeclared identifier, and the same for GL_TEXTURE_WRAP_R.

Where can I find these enums? Or do I have to define them myself from the OpenGL 1.2 specs values?

Thanks for your help

Siwko: Either those examples are wrong, or you are misreading the examples. Chances are the function pointer is being recasted before being used.

[This message has been edited by DFrey (edited 03-31-2001).]

Originally posted by ffish:

Where can I find these enums? Or do I have to define them myself from the OpenGL 1.2 specs values?

Hi ffish. Here are those enumerants:
GL_TEXTURE_3D = $806F;

DFrey: AFAIK my code is alright. Here’s a snippet:

#ifdef _WIN32
// Prepare a function pointer to hold the glTexImage3D pointer.
typedef void (*PFNglTexImage3D) (GLenum target, GLint level, GLint internalFormat,
GLsizei width, GLsizei height, GLsizei depth,
GLint border, GLenum format, GLenum type,
const GLvoid *texels);

// Call wglGetProcAddress to get a pointer to the function.
PFNglTexImage3D glTexImage3D = (PFNglTexImage3D) wglGetProcAddress("glTexImage3D");
assert(glTexImage3D != 0);

// GLenum GL_TEXTURE_3D = 0x806F;
// GLenum GL_TEXTURE_WRAP_R = 0x8072;
#endif // a win32 system.

The GLenums that Alexei_Z pointed out seem to work but just like you said DFrey, the pointer seems to be recast before use. Any more hints?

Thanks again

[This message has been edited by ffish (edited 03-31-2001).]

ffish: I was responding to Siwko.

But with regard to your problem, yes, you need to define those enumerants. You can get the latest gl header from SGI that includes those definitions. I can’t remember the url to the relevant link, but I know NVIDIA has it posted on the dev site.

DFrey: oops, so I’m not the center of the universe?

Thanks for the tip re the headers. I’ll look for them tomorrow (midnight in Australia now)

Nite everyone

First, I don’t appreciate being called a liar.

First off… the document in question is:

Secondly, as for the reson why it doesn’t compile is because it isn’t legal C++ syntax. If it were a simple C application, using the aforementioned method would work just fine. In case you’re wondering, the answer as to why (which I was looking for) this wasn’t working is here:

The above link states the typing conventions for GetProcAddress and FARPROC, and why that code works in C and not in C++.


Interesting. Learn something new all the time. It has been a long time since I’ve worked with pure C, but I never knew that about the empty parenthesis before.

Nor did I. Well, at least that bizarre behavior was corrected with C++.

Just try this:
typedef void (*MYFARPROC)(…);

In C++ you have to write (…) to allow a variable amount of parameters. In C you could simply write ().

A good example on this is the prototype of printf:
int printf(const char*, …)