Click here to Skip to main content
13,702,775 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
i have script control in vb and there we have few functions like Run:

SCR.Timeout = 10000
SCR.Run "Main"

same thing i am doing in c+ where we have scrip control object ocx i tried to use that the same way in vb , but iam getting issue.

because i dont known how to pass safeparamter in run function as in vb only there are passing one paramter:

i tried the below code it is crashing in invoke helper . please let me known how can we do ?

What I have tried:

teststt.put_Language(_T("VBScript"));

LPSAFEARRAY psa;
SAFEARRAYBOUND rgsabound[] = { 1, 0 }; // 3 elements, 0-based

int i;

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

VARIANT vFlavors[1];
for (i = 0; i < 1; i++)
{
    VariantInit(&vFlavors[i]);
    V_VT(&vFlavors[i]) = VT_BSTR;
}

V_BSTR(&vFlavors[0]) = SysAllocString(OLESTR(""));
//V_BSTR(&vFlavors[1]) = SysAllocString(OLESTR(""));
//V_BSTR(&vFlavors[2]) = SysAllocString(OLESTR(""));

long lZero = 0;
//long lOne = 1;
//HRESULT hr;
//long lTwo = 2;

//// Put Elements to the SafeArray:
HRESULT hr = SafeArrayPutElement(psa, &lZero, &vFlavors[0]);
//hr = SafeArrayPutElement(psa, &lOne, &vFlavors[1]);
//hr = SafeArrayPutElement(psa, &lTwo, &vFlavors[2]);

//// Free Elements from the SafeArray:
for (i = 0; i < 1; i++)
{
    SysFreeString(vFlavors[i].bstrVal);
}
/*teststt.AddCode(
    _T("function Main()"));*/

teststt.put_AllowUI(TRUE);
CString lsCode = _T("Sub Main()") + CString("\r\n") + "       Dim WshShell" + "\r\n" + "       Set WshShell = CreateObject(\"Wscript.Shell\")" + "\r\n" + "       WshShell.Run \"c:\\windows\\calc.exe\"" + "\r\n" + "End Sub";// JUST FOR TEST PURPOSE

teststt.AddCode(lsCode);
teststt.put_Timeout(10000);
VARIANT l  = teststt.Run(_T("Main"), &psa);
Posted 13-Sep-18 18:28pm
Updated 13-Sep-18 20:58pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

The code is a bit strange, but first settting the language and THAN reset should be the wrong order.

Take a look at this SafeArrayCreate example.

You should use a BSTR for the AddCode parameter.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web06-2016 | 2.8.180906.1 | Last Updated 14 Sep 2018
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100