DLLNotFoundException: C++ OpenGL code

Hi everyone.

I’ve created a small DLL to write to a texture directly from opengl without having to rely on the slow SetPixel/Apply functionality in Unity.

However, I’m having a problem of DLLNotFoundException.

Having searched around for a while, I’ve found multiple entries around this problem. However, looking at others working to get the same thing done, they have obviously done it :wink:

The code I have is:


#define EXPORT __declspec(dllexport)

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <gl/gl.h>

extern "C"
	 extern EXPORT void updateTexture ( int texId, char* cvFeed, int w, int h );

CPP file:

#include "GLCalls.h"

extern "C"
	extern EXPORT void updateTexture ( int id, char* ptr, int width, int height )
		glBindTexture( GL_TEXTURE_2D, id );
		glTexSubImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) ptr );

Compiling goes just fine, and everything looks just dandy… Until I enter and run in Unity, in which the code looks like this:

[DllImport(DLL.GL_DLL.path, EntryPoint = "updateTexture")]
    internal static extern void UpdateTexture(int texId, IntPtr cvFeed, int w, int h);

feed.updateTexture(texId, imgPtr, width, height);

Now… I’ve created a couple of DLL’s that is already running fine in Unity (other C++ and OpenCV stuff)… not a problem there.

Things I have tried:

  • Editor is already set to -force-opengl
  • I have gone through the DLL in dependency walker (can easily find the gl calls)
  • I’ve tried to add opengl.dll (and even re-coded the dll using glut and glew, and tried adding glut32.dll and glew32.dll) to the editor folder.
  • Removing the gl calls from the DLL and recompiling, in which case Unity can easily load it.

No luck. in getting gl calls to work.

I’m suspecting no static linking, and Unity (for some reason) not being able to load/find the opengl/glut32/glew32 dll files.

I’m working in Windows XP SP3, using Unity 3.4 Pro Trial, and Visual Studio 2008 Pro.

Anyone care to chip in… I’m kinda clueless about how to fix this.

DLLNotFoundException, from what I read, means what it says: the DLL wasn’t found (though it might be something else, I guess tackle the obvious thing first). Is the DLL in your Assets folder? And what is DLL.GL_DLL.Path? (In my experience, it just needs to be the base name of your DLL- so if your DLL is in ‘Assets/plugin.dll’, your DLLImport name should just be ‘plugin’).

I’ve built OpenGL DLLs on Windows before; all you need to link should be opengl32.dll.

Relatedly, you should use the __stdcall calling convention for your exported functions. That’s what Mono expects on Windows.