- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个从 VB/Excel 运行的程序,并在其中执行一个 C++ 程序。我有两个(我认为相关的)问题:
我从 C++ 程序执行时捕获返回值,但我得到的数字不是零(而是一个 4 位整数值,我收到的示例值是 8156、5844、6100 , 5528).我确定程序正常退出时代码为 0,但我认为 VB 在 C++ 程序完成执行之前获得了它的值——这可以解释为什么我没有获得零值,以及我如何获得最终的、正确的从我的 C++ 程序返回值?
[可能作为 #1 的解决方案] 如何让 VB 程序“暂停”,直到 C++ 模型完成执行?模型完成后,我需要做一些额外的 VB 工作(基于 C++ 模型运行的输出配置)
这是我的模型调用方式的 VB 代码。我正在通过 Windows shell 运行一个完整编译的 C++ 程序。
'---------------------------------------------------------
' SECTION III - RUN THE MODEL AS C++ EXECUTABLE
'---------------------------------------------------------
Dim ModelDirectoryPath As String
Dim ModelExecutableName As String
Dim ModelFullString As String
Dim ret As Long
ModelDirectoryPath = Range("ModelFilePath").value
ModelExecutableName = Range("ModelFileName").value
ModelFullString = ModelDirectoryPath & ModelExecutableName
' Call the model to run
Application.StatusBar = "Running C Model..."
ModelFullString = ModelFullString & " " & ScenarioCounter & " " & NumDeals _
& " " & ModelRunTimeStamp
ret = Shell(ModelFullString)
' Add error checking based on return value
' This is where I want to do some checks on the return value and then start more VB code
最佳答案
1) 您正在捕获程序的任务 ID(这是 Shell() 返回的内容)而不是打开程序的任何返回 - 这就是为什么它是一个 4 位数字
2) Shell() 异步运行所有程序。
要同步运行程序或运行它并等待返回,要么:
使用 Windows API 函数(我建议您引用 https://stackoverflow.com/a/5686052/1101846 以获取您可以使用的选项/API 调用列表)
更容易的是,使用 Windows 脚本宿主提供的 WshShell 对象(请参阅 https://stackoverflow.com/a/8906912/1101846 了解更多示例,而不是我在下面给出的示例)。在 http://msdn.microsoft.com/en-us/library/d5fk67ky 查看 Run 方法的 Microsoft 文档
基本上,做类似的事情:
Set o = CreateObject("WScript.Shell")
valueReturnedFromYourProgram = o.Run( _
strCommand:="notepad", _
intWindowStyle:=1,
bWaitOnReturn:=true)
Debug.Print valueReturnedFromYourProgram
关于c++ - 在 VB 和 C++ 之间控制程序流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18213357/
我正在制作一个 html/javascript 浏览器主页,它可以下载到任何计算机上——您只需从您的计算机上运行 *.html 文件,它就会在您的默认浏览器中打开;在其中你有一个紧凑的主页,有几个选项
我是一名优秀的程序员,十分优秀!