Marshalling a function pointer to a delegate without .NET 2.0

  • Thread starter Thread starter Jason Bell
  • Start date Start date
J

Jason Bell

I know this functionality already exists in .NET 2.0 via
Marshal.GetDelegateForFunctionPointer, but I'd rather not force my users to
use a beta framework (not to mention the fact that I'm still using good old
vs .net 2002, that refuses to use the 2.0 framework).

Specifically, I'm using an external declaration of the Simple Directmedia
Library function SDL_GL_GetProcAddress to acquire the procedure addresses
of OpenGL extensions. Unfortunately, you can't make simple external
declarations for them. In other languages you simply acquire function
pointers to them.

This is the external declaration for SDL_GL_GetProcAddress:

[DllImport("sdl.dll", EntryPoint = "SDL_GL_GetProcAddress")]
public static extern IntPtr GetProcAddress(string funcname);

You provide the name of the extension function, and the return value is a
pointer to that function.

I'm willing to use the unsafe version as well, I'll just wrap it in a safe
wrapper to make sure it's CLS compliant.

[DllImport("sdl.dll", EntryPoint = "SDL_GL_GetProcAddress")]
private unsafe static extern void * GetProcAddress(string funcname);

So how would one go about marshaling the function pointer to a delegate in
1.0 or 1.1? Surely there's some roundabout way of doing it.
 
So how would one go about marshaling the function pointer to a delegate in
1.0 or 1.1?

The simple answer is that you can't do it. The easiest solution is to
write a wrapper in a language that supports calling functions by
function pointer (such as C++).



Mattias
 
Yeh I figured I'd wind up writing an unmanaged library, at least until 2.0
is the standard. I had just hoped there was some circuitous route in .NET
that allowed you to call an unmanaged function pointer.

Thanks for the help.
 
Back
Top