Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
1.00/5 (1 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
Updated 13-Sep-18 20:58pm
v2

1 solution

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.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900