调用非托管DLL时,vshost32.exe崩溃

时间:2022-02-18 07:32:26

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 be accessed, and I can work with the functions in the DLL.

我正在使用VS 2005应用程序与非托管(Fortran)DLL进行交互。当我直接从命令行运行编译的可执行文件时,一切都很好 - 可以访问DLL,我可以使用DLL中的函数。

Unfortunately, when I launch the app from VS 2005, I get a popup stating "vshost32.exe has stopped working" and no useful debugging information.

不幸的是,当我从VS 2005启动应用程序时,我得到一个弹出窗口,声明“vshost32.exe已停止工作”并且没有有用的调试信息。

Has anyone experienced this behavior, or know why this might be occuring? I can't figure out why it would run fine when launched stand-alone, but not via vshost32.

有没有人经历过这种行为,或者知道为什么会出现这种情况?我无法弄清楚为什么它在单独启动时运行正常,但不能通过vshost32运行。

(One last note: I am using .local files to force registered dlls to be used from cwd, but this particular dll is not registered. I'm just noting it here in case it helps.)

(最后一点说明:我正在使用.local文件强制从cwd使用已注册的dll,但是这个特殊的dll没有注册。我只是在这里注意它以防它有帮助。)


Thanks very much,

非常感谢,

Mike

5 个解决方案

#1


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

我遇到了vshost32.exe崩溃的问题,当我选中复选框时,问题就消失了:

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)

编辑:在更新的版本中调用该选项:启用本机代码调试(感谢Qwerty01)

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

编辑:它似乎也有助于VS2008(@Deacon Frost),VS2010(@Alxandr)。

#2


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

不确定,但您可以禁用属性 - >调试中使用visual studio托管过程

#3


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.

根本问题的原因是您在调试时可能有一个不同的工作文件夹,因此找不到您的本机库。

#4


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.

我使用的是Visual C#2010 Express。我可以通过导航到Project - > Properties来阻止vshost32崩溃。我单击Debug选项卡并取消选中“启用Visual Studio托管过程”复选框。

#5


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.

下载依赖性walker http://www.dependencywalker.com/使用它来打开你的dll,看看它是否依赖于该文件夹中不存在的其他dll。

#1


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

我遇到了vshost32.exe崩溃的问题,当我选中复选框时,问题就消失了:

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)

编辑:在更新的版本中调用该选项:启用本机代码调试(感谢Qwerty01)

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

编辑:它似乎也有助于VS2008(@Deacon Frost),VS2010(@Alxandr)。

#2


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

不确定,但您可以禁用属性 - >调试中使用visual studio托管过程

#3


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.

根本问题的原因是您在调试时可能有一个不同的工作文件夹,因此找不到您的本机库。

#4


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.

我使用的是Visual C#2010 Express。我可以通过导航到Project - > Properties来阻止vshost32崩溃。我单击Debug选项卡并取消选中“启用Visual Studio托管过程”复选框。

#5


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.

下载依赖性walker http://www.dependencywalker.com/使用它来打开你的dll,看看它是否依赖于该文件夹中不存在的其他dll。