As a follow-up to my recent question about .NET Compact Framework debugging, I am currently trying to use OpenGL ES from both a .NET Compact Framework and a .NET Framework application. I use this wrapper, which has been created for OpenGL ES and imports from libGLES_CM.dll.
To make debugging easier, I created a .NET Framework application, recreated the import project for OpenGL ES and EGL with the same files (just building for Desktop framework), created constants for the DLL names so they'll import from libGLESv2.dll and libEGL.dll on Windows and from libGLES_CM.dll on CF. The DLLs are from the PowerVR OpenGL ES Emulation SDK (the target device has a PowerVR SGX) and are just a OpenGL ES wrapper around the real OpenGL implementation. And here comes the problem:
In the wrapper library, the OpenGL functions are in two static classes (gl and egl) and have the usual name, but without the gl/egl prefix, so calling them would be egl.GetDisplay()
instead of egl.eglGetDisplay()
. They are imported like this:
[DllImport(DllName, EntryPoint = "eglGetDisplay")]
static extern IntPtr GetDisplay(EGLNativeDisplayType display_id);
This works fine on the Compact Framework. In the desktop project, an EntryPointNotFoundException is thrown - because the functions are named like _eglGetDisplay@4
(side note: the WMD catches Alt-Gr+Q for blockquotes, which is the at symbol on German keyboard layouts. I had to paste this one.) according to Dependency Walker.
I managed to get the underscore added to the function name for the desktop project, but not for the CF one, by conditionally setting a string constant to empty string or "_", and concatenating it and the entry point name, so it looks like this:
[DllImport(DllName, EntryPoint = FunctionPrefix + "eglGetDisplay")]
No problem here. But the function is still not found, because the @4 (what exactly is that?) is missing. If I add the @4, this works, but since all functions have different values here, I had to do this by hand and likely the numbers wouldn't be correct for the CF version. Here comes the strange part:
If I just don't specify the entry point and instead name the function like it should be named, the import works fine! Now this is ugly because of the double prefix (static class name and function name), though I could get around this by just adding a wrapper for this one. Since I won't rely heavily on these functions (need only a rather simple 2D engine), this wouldn't be a problem, but it just doesn't feel right.
Why doesn't it work when specifying the entry point? What can I do to make it work like it should?