Click here to Skip to main content
13,832,971 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:


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++)
    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;
//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++)
    _T("function Main()"));*/

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

VARIANT l  = teststt.Run(_T("Main"), &psa);
Updated 13-Sep-18 21:58pm

1 solution

Rate this: bad
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.

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
Web01 | 2.8.190114.1 | Last Updated 14 Sep 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

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