How to run vbscript from C++ code?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sandeepkavade
    New Member
    • Mar 2007
    • 30

    How to run vbscript from C++ code?

    Hi all,
    How to vb script from a C++ code.

    the script is like:

    Function execute()
    .
    .
    .
    .
    .
    .
    .
    execute = obj.xml 'obj.xml is a xml
    End Function

    the script is working fine if i write it in a vbs file and double click on it.
    but how to call it from a C++ code.

    I tried with IScriptControl: :Run but the its not giving any output.

    SAFEARRAYBOUND rgsabound[] = { 0, 0 }; // 0 elements, 0-based
    USES_CONVERSION ;

    psa = SafeArrayCreate (VT_VARIANT, 1, rgsabound);
    if (!psa)
    {
    return E_OUTOFMEMORY;
    }

    _variant_t outpar = m_pScriptContro l->(m_bstrFunctio n, &psa);
    // _bstrFunction = execute

    but after execution of this statement outpar is empty.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Can you not use a system call?

    [code=cpp]
    system("myfile. vbs");
    [/code]

    Comment

    • sandeepkavade
      New Member
      • Mar 2007
      • 30

      #3
      Originally posted by weaknessforcats
      Can you not use a system call?

      [code=cpp]
      system("myfile. vbs");
      [/code]

      I havent tried with system().
      i was using the same code previously but at that time i was creating xml by concatnation of values like
      resultset = resultset & "<row "
      resultset = resultset & value
      resultset = resultset & "/>
      and then
      execute = resultset

      at that time the function IScriptControl: :Run() gives me what i was expecting. but now i changed the script which generate the xml directly using a COM dll (the dll is registered) but now Run() is failing.
      Again if i write the same script in file with message box to display the xml and run it by double clicking it, i can see the results on messagebox means there is no problem with the new xml generator object. it is doing his job. but dont know why Run() is failing?

      Comment

      Working...