vshost32.exe crash when calling unmanaged DLL

前端 未结 5 1143
野性不改
野性不改 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.

    0 讨论(0)
  • 2020-12-10 09:06

    I am using Visual C# 2010 Express. I was able to stop the vshost32 crashes by navigating to Project -> Properties. I clicked on the Debug tab and unchecked the "Enable the Visual Studio hosting process" checkbox.

    0 讨论(0)
  • 2020-12-10 09:14

    I had problem with crashes of vshost32.exe the problem vanished when I checked the checkbox:

    Properties -> Debug -> Enable unmanaged code debugging

    Does it work for you?

    EDIT: In more recent versions the option is called: Enable native code debugging (thanks Qwerty01)

    EDIT: It also seems to help in VS2008 (@Deacon Frost), VS2010 (@Alxandr).

    0 讨论(0)
  • 2020-12-10 09:14

    Not sure but you can disable use of the visual studio hosting process from Properties -> Debug

    0 讨论(0)
  • 2020-12-10 09:19

    download dependency walker http://www.dependencywalker.com/ use it to open up your dll, and see if it relies on other dlls that are not present in that folder.

    0 讨论(0)
提交回复
热议问题