Run a Visual C++ program from VB Script and get a return value ??
-
Hi all, Im currently developing a MFC-program in Visual C++ 6.0 that will identifiy a user through his/hers fingerprint. The C++ program needs to be launched from another program with VBA support (so Im currently testing it in MS Excel) The C++ program also needs to return a textstring with the username (or ID or some kind of text like "George Lucas") With my very basic skills in VBScript I have manged to run the C++ program. But is it possible to get something back from the program ?? Im guessing that the C++ program might need some kind of method to communicate back to the VB Script ... ? Im would be very thankful for any kind of help ! / daniel
-
Hi all, Im currently developing a MFC-program in Visual C++ 6.0 that will identifiy a user through his/hers fingerprint. The C++ program needs to be launched from another program with VBA support (so Im currently testing it in MS Excel) The C++ program also needs to return a textstring with the username (or ID or some kind of text like "George Lucas") With my very basic skills in VBScript I have manged to run the C++ program. But is it possible to get something back from the program ?? Im guessing that the C++ program might need some kind of method to communicate back to the VB Script ... ? Im would be very thankful for any kind of help ! / daniel
I have a VB project that loads a C++ DLL. Declare the following module level API functions in your VB project. ' -- Windows API Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long ' -- Public function in C++ DLL Public Declare Function Test Lib "mycdll.dll" Alias "test_vb" () As Long To use the C++ function you can use something like the following. Note: strDLL holds the fullpath to the C++ DLL ' -- Load the dll lngRet = LoadLibrary(strDLL) ' -- Check for success If lngRet <> 0 Then ' -- Run the script Msgbox Test Else MsgBox "Could not load dll '" & strDLL & "'" & DEF_SPACE, vbCritical, DEF_APP_TITLE GoTo PROC_EXIT End If PROC_EXIT: ' -- Clean up If lngRet <> 0 Then FreeLibrary lngRet
-
Hi all, Im currently developing a MFC-program in Visual C++ 6.0 that will identifiy a user through his/hers fingerprint. The C++ program needs to be launched from another program with VBA support (so Im currently testing it in MS Excel) The C++ program also needs to return a textstring with the username (or ID or some kind of text like "George Lucas") With my very basic skills in VBScript I have manged to run the C++ program. But is it possible to get something back from the program ?? Im guessing that the C++ program might need some kind of method to communicate back to the VB Script ... ? Im would be very thankful for any kind of help ! / daniel
You can do that using the Exec method of the WScript.Shell object. The Exec method will return a WshScriptExec object that can be used to monitor the status of the running program, its exit code, and get to it StdIn, StdOut, and StdErr streams. The docs on the WshShell.Exec method start here[^].
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("MyCApp.exe")Do While oExec.Status = 0
WScript.Sleep 100
LoopWScript.Echo oExec.ExitCode
RageInTheMachine9532
-
I have a VB project that loads a C++ DLL. Declare the following module level API functions in your VB project. ' -- Windows API Public Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long ' -- Public function in C++ DLL Public Declare Function Test Lib "mycdll.dll" Alias "test_vb" () As Long To use the C++ function you can use something like the following. Note: strDLL holds the fullpath to the C++ DLL ' -- Load the dll lngRet = LoadLibrary(strDLL) ' -- Check for success If lngRet <> 0 Then ' -- Run the script Msgbox Test Else MsgBox "Could not load dll '" & strDLL & "'" & DEF_SPACE, vbCritical, DEF_APP_TITLE GoTo PROC_EXIT End If PROC_EXIT: ' -- Clean up If lngRet <> 0 Then FreeLibrary lngRet
-
You can do that using the Exec method of the WScript.Shell object. The Exec method will return a WshScriptExec object that can be used to monitor the status of the running program, its exit code, and get to it StdIn, StdOut, and StdErr streams. The docs on the WshShell.Exec method start here[^].
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("MyCApp.exe")Do While oExec.Status = 0
WScript.Sleep 100
LoopWScript.Echo oExec.ExitCode
RageInTheMachine9532