470,864 Members | 1,834 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,864 developers. It's quick & easy.

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

psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
if (!psa)

_variant_t outpar = m_pScriptControl->(m_bstrFunction, &psa);
// _bstrFunction = execute

but after execution of this statement outpar is empty.
Feb 20 '08 #1
2 12980
9,208 Expert Mod 8TB
Can you not use a system call?

Expand|Select|Wrap|Line Numbers
  1. system("myfile.vbs");
Feb 20 '08 #2
Can you not use a system call?

Expand|Select|Wrap|Line Numbers
  1. system("myfile.vbs");

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?
Feb 21 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Dan | last post: by
2 posts views Thread by duncan | last post: by
6 posts views Thread by rishabhshrivastava | last post: by
3 posts views Thread by ashishp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.