DllNotFound Exception when I use glut functions in my Dll

自作多情 提交于 2019-12-25 05:49:18

问题


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();
}

回答1:


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




回答2:


 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.




回答3:


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



来源:https://stackoverflow.com/questions/5743895/dllnotfound-exception-when-i-use-glut-functions-in-my-dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!