EthanHunt
EthanHunt

Reputation: 463

DllNotFound Exception when I use glut functions in my Dll

I have a c++ dll and c# application. In C# application I call function from dll. With simple function like:

extern "C"
{
    __declspec(dllexport) void HelloFromDll()
    {
        MessageBox(NULL, _T("Hello from DLL"), _T("Hello from DLL"), NULL);
    }
}

all works fine. When i use function with glut like this:

extern "C"
{
    __declspec(dllexport) int InitGlut()
    {
        glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
        glutInitWindowPosition(100,100);
        glutInitWindowSize(320,320);
        glutCreateWindow("MyWindow");
        glutDisplayFunc(renderScene);
        glutMainLoop();
        return 0;
    }
}

i get DllNotFound Exception. Why? C# code:

const string pathToDll = "../../../Release/MyDLL.dll";
[DllImport(pathToDll)]
public static extern void HelloFromDll();
[DllImport(pathToDll)]
public static extern int InitGlut();

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    HelloFromDll();
    InitGlut();
}

Upvotes: 0

Views: 437

Answers (3)

Hans Passant
Hans Passant

Reputation: 941218

 const string pathToDll = "../../../Release/MyDLL.dll";

Odds are not great that this would be a valid path. Or that it helps Windows find any dependent DLLs, it doesn't. What's much worse is that the odds are zero after you deployed your app.

Add a post build event to your project that copies all the required native DLLs into the $(TargetDir) directory with xcopy /d /y. Windows always looks there first. And it will work both when you debug and after you deploy. And your build directory contains everything you need to deploy.

Upvotes: 1

weismat
weismat

Reputation: 7411

Look here.
The name of the DLL and the path need to be split as shown there...

Upvotes: 0

Aykut Çevik
Aykut Çevik

Reputation: 2088

Set your working directory of your application to the path of the DLL's, this should solve your problem.

Upvotes: 1

Related Questions