- Home /
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 ;)
The code I have is:
Header:
#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.
Answer by boat365 · Sep 14, 2011 at 08:53 AM
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.
Oh- I see you say that if you remove the GL calls you can load the DLL. In which case I'm stumped: though I say again, this does work, and just by linking opengl32.dll.
Actually, scratch that again: I'm not sure I've actually seen this work on Windows. It does work on $$anonymous$$acOS, such as what that's worth.
Well, I will have to try it out on OSX one day then. I even tried building it to a standalone, hoping it was the editor not allowing me to get the dll, with no luck :(
I've just realized; the editor won't let you -force-opengl anyway- that only works for standalones (according to the docs at least).
Anyway, I've put together a project that works on my system. I'm not sure how to post it on here though, so I've stuck it up on dropbox here: http://dl.dropbox.com/u/7654998/gltex.zip
Your answer
Follow this Question
Related Questions
use [DllImport("xxxx")] for .so with other .so 0 Answers
Using uEye Cameras in an Extension on a 64-bit machine 4 Answers
DLLNotFoundException - C++ plugin 1 Answer
Nvidia Ansel integration Issue :: DllNotFoundException 1 Answer
DLLNotFoundException 0 Answers