Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Run a Visual C++ program from VB Script and get a return value ??

Run a Visual C++ program from VB Script and get a return value ??

Scheduled Pinned Locked Moved Visual Basic
c++testingbeta-testingtools
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bjolletts
    wrote on last edited by
    #1

    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

    T D 2 Replies Last reply
    0
    • B bjolletts

      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

      T Offline
      T Offline
      TheAphextwin
      wrote on last edited by
      #2

      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

      B 1 Reply Last reply
      0
      • B bjolletts

        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

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        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
        Loop

        WScript.Echo oExec.ExitCode

        RageInTheMachine9532

        B 1 Reply Last reply
        0
        • T TheAphextwin

          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

          B Offline
          B Offline
          bjolletts
          wrote on last edited by
          #4

          thank you, I'll look in to it

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            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
            Loop

            WScript.Echo oExec.ExitCode

            RageInTheMachine9532

            B Offline
            B Offline
            bjolletts
            wrote on last edited by
            #5

            Getting access to the StdOut would be great, thank you very much ! *edit* Got it working now, thanks a bunch !

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups