PDA

View Full Version : using opengl32.dll and glew32.dll on c#



laobrasuca
09-26-2010, 05:06 PM
Hi all,

i'm implementing an opengl application on c#. I wrap opengl functions like in TAO/OpenTK framework, i.e., for context/device creation i'm using functions like wglCreateContext, wglGetCurrentDC, SetPixelFormat, SwapBuffers, ChoosePixelFormat, GetDC, among others with direct dll imports DllImport("dll.dll"...) from system's user32.dll, gdi32.dll, kernel32.dll and opengl32.dll. Similarly I wrap opengl functions i need directly with [DllImport("opengl32.dll")]. So far it works just fine, nothing to complain about.

However, i got to add an additional dll (let's call it lao.dll) to my c# application (thus importing lao.dll's external functions with [DllImport("lao.dll")]). Inside of lao.dll i have some calls to opengl functions, like glGetFloatv, glBindBuffer, etc. To build this dll i'm using glew.h, glew32.lib. (In the c# application runtime i add glew32.dll to its path). Well, thing is that my application stop running whenever i call a funtion from lao.dll that uses opengl functions. There's no errors, no crashes, it just doesn't do anything! (i still can click buttons, resize window and so on.) In the debug mode, it's the same, no errors but i can't go further on the execution. I was expecting to be able to do opengl manipulation on this dll but it seems either that i'm doing things in a wrong way or that it's just impossible.

Have you folks any suggestion on how to get it working?

thx, lao

laobrasuca
09-28-2010, 03:22 AM
OK, I've done some changes (mostly the order in which things are called) and now I'm getting an error ;) It is this one: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. (whenever I use an opengl function inside my dll)

Could this be 'cause of the fact that in c# I'm using opengl32.dll and for my dll I'm using glew32.dll? If I simply delete glew32.dll from the .exe folder, I get an error saying it is not possible to load my own dll (System.DllNotFoundException). If I copy and paste opengl32.dll in my own folder, it will crash with the same error.

I wonder how can I build my dll without using glew but directly using opengl32.lib/opengl32.dll/gl.h/gl3.h or whatever thing that don't need any additional wrapping. I mean, a similar thing as in c#, 'cause in c# I myself import functions straight from opengl32.dll