Scrip控件VB和C ++ [英] Scrip control VB and C++

查看:69
本文介绍了Scrip控件VB和C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在vb中有脚本控制,在那里我们有很少的功能,如运行:



SCR.Timeout = 10000

SCR.Run 主要



同样我在c +中做的事情我们有脚本控制对象ocx我试图在vb中使用相同的方式,但是我遇到了问题。



因为我不知道如何在运行函数中传递safeparamter,就像在vb中只传递一个参数:



i尝试了以下代码,它在调用助手时崩溃了。请让我知道我们该怎么做?



我尝试过:



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);

推荐答案

代码有点奇怪,但首先设置语言并 THAN 重置应该是错误的订单。



看看这个 SafeArrayCreate示例



您应该使用BSTR作为AddCode参数。
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.


这篇关于Scrip控件VB和C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆