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.
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.