vshost32.exe crash when calling unmanaged DLL

前端 未结 5 1147
野性不改
野性不改 2020-12-10 08:27

I\'m using a VS 2005 app to interface against an unmanaged (Fortran) DLL. When I run the compiled executable straight from the command line, everything is fine - the DLL can

5条回答
  •  庸人自扰
    2020-12-10 09:04

    Might be that there is an unhandled exception. You could try to add the following code to handle all uncatched exceptions:

    static void Main()
    {
      // Add a handler for the UnhandledExceptionEvent
      AppDomain.CurrentDomain.UnhandledException +=
        new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
    
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new Form1());
    }
    
    static void CurrentDomain_UnhandledException
         (object sender, UnhandledExceptionEventArgs e)
    {
        try
        {
            Exception ex = (Exception)e.ExceptionObject;
    
            MessageBox.Show(ex.ToString(), "Error", 
                  MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }
        finally
        {
            Application.Exit();  
        }
    }
    

    The reason for the underlying problem is that you might have a different working folder when debugging so that your native library is not found.

提交回复
热议问题