C# 使用WshShell从VBA运行.NET应用程序时出现溢出错误
为什么要用以下代码启动.NET应用程序QCSearch.exe:C# 使用WshShell从VBA运行.NET应用程序时出现溢出错误,c#,.net,vba,wsh,exit-code,C#,.net,Vba,Wsh,Exit Code,为什么要用以下代码启动.NET应用程序QCSearch.exe: Private Sub StartQCSearch() Dim wsh As WshShell Dim waitOnReturn As Boolean: waitOnReturn = True Dim windowStyle As Integer: windowStyle = 1 Dim errorCode As Integer Dim pth As String Set
Private Sub StartQCSearch()
Dim wsh As WshShell
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
Dim errorCode As Integer
Dim pth As String
Set wsh = New WshShell
pth = ThisWorkbook.Path & "\QCSearch.exe"
// Following line is marked, when debugging error 6:
errorCode = wsh.Run(pth, windowStyle, waitOnReturn)
If errorCode <> 0 Then
MsgBox "QCSearch.exe exited with error code " & errorCode & "."
End If
End Sub
用c编写的.NET应用程序有一个主窗体,可以打开一个对话框。
当我确认此对话框时,出现错误6,.NET应用程序立即关闭
对话框似乎返回了一些errorCode无法分配的退出代码。
但是正如我所说的,我检查了我的.NET应用程序的退出代码,但是,它们通常不应该通过关闭任何对话框来返回,而是通过关闭主窗体来返回
此外,在调试错误后,errorCode变量仍被赋值为0
提前谢谢你的帮助
更新:
当.NET应用程序从Windows CMD启动时,它也会在确认对话框后中断。现在,我真的很困惑。有人知道为什么Internal dialog会关闭整个应用程序吗?好的,如果您使用.NET应用程序中的相对路径,请永远不要忘记这样做:
wsh.CurrentDirectory = ThisWorkbook.Path
如果这是您想要的,您应该将其标记为问题的答案。对你自己的问题标记你自己的答案是可以的。好的,但我只允许在两天内这样做。