|
Hi,
I using this article. (VC++)
I wrote script like below.
But Error MSG --> "'Sleep' Src: Microsoft VBScript runtime error Scode: 800a000d "
How to use 'Sleep()' , in 'Do While ~ Loop'
Sub Bit
Dim DIVal
Do While 1
DIVal = GetTagVal("ETOS_RCS.DI")
if DIVal >=1 then
Call SetTagVal(1, "ETOS_RCS.DI1")
else
Call SetTagVal(0, "ETOS_RCS.DI1")
end if
Sleep 1000
Loop
End Sub
|
|
|
|
|
Hi
I want to run the script host in the another thread. because I want to support some "sleep" function in the script and while it is sleeping, I want the Mainthread is working for processing messages.
My main thread has CoInitializeEx(NULL, COINIT_MULTITHREADED). and I have created script thread from the CWinthread and It has CoInitialize(NULL);
but if i call the AddScriptCode from the mainthread, It returns error "8000ffff"
so I did some marshaling with GIT, but it also returns "800706f4" (A null reference pointer was passed to the stub)
Is there any good way for supporting threaded script host? or do you have any idea for supporting sleep function?
|
|
|
|
|
Hi
I really want to use the bytes arrays for event argument...
but, There is typemismatch in the VBScript.. Somebody help me!!
below is what i trying to do from web-search, Is there any simple way?
VARIANT var;
VariantInit(&var); var.vt = VT_ARRAY | VT_UI1; SAFEARRAYBOUND rgsabound[1]; rgsabound[0].cElements = 12;
rgsabound[0].lLbound = 0;
var.parray = SafeArrayCreate(VT_UI1,1,rgsabound); if(var.parray != NULL)
{
void * pArrayData = NULL;
SafeArrayAccessData(var.parray,&pArrayData); memcpy(pArrayData, pBuf, 10); SafeArrayUnaccessData(var.parray);
COleVariant vtStr(var);
g_pFrame->m_ScriptProxy.FireOnMessage(vtStr);
VariantClear(&var);
}
Sub ScriptHost_OnMessage(msg)
If isArray(msg)Then
Display "It's an array, yay" -> Fine
Else
Display "Not an array, bad"
End If
Display ubound(msg)
Display msg(0) -> typemismatch error
End Sub
|
|
|
|
|
Did you check the error return code?
Check:
1) SafeArrayCreate(VT_UI1, 1, &rgsabound);
2) Maybe thread issue: COleVariant destructor will clear the array.
|
|
|
|
|
1. SafeArrayCreate(VT_UI1, 1, rgsabound); is okay, its return is not null.
2. I have changed COleVariant as a class member for not destroing. but it is not solved.
Ernest, Can we use the byte array as the event argument?
(String is okay, but I want some byte array for numeric comparison)
Is there any sample codes?, because I am not sure and afraid. I can do it....
|
|
|
|
|
I haven't tried passing values to VB code but calling your own interface should probably work.
You may be into something, I don't think you can pass byte array.
|
|
|
|
|
If not, Can we pass the multiful argument to script? (VB or Java anythingelse)
I have tried like below, but it seems only first argument is working
....
[id(5)] void OnMessage8b(VARIANT vtB0, VARIANT vtB1, VARIANT vtB2, VARIANT vtB3, VARIANT vtB4, VARIANT vtB5, VARIANT vtB6, VARIANT vtB7);
....
EVENT_CUSTOM("OnMessage8b", FireOnMessage8b, VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT VTS_VARIANT)
....
void FireOnMessage8b(const VARIANT FAR& vtB0, const VARIANT FAR& vtB1, const VARIANT FAR& vtB2, const VARIANT FAR& vtB3,
const VARIANT FAR& vtB4, const VARIANT FAR& vtB5, const VARIANT FAR& vtB6, const VARIANT FAR& vtB7)
{FireEvent(eventidOnMessage8b,EVENT_PARAM(VTS_VARIANT), &vtB0, &vtB1, &vtB2, &vtB3, &vtB4, &vtB5, &vtB6, &vtB7);}
...
m_ScriptProxy.FireOnMessage8b(vtB0, vtB1, vtB2, vtB3, vtB4, vtB5, vtB6, vtB7);
...
function ScriptHost::OnMessage8b(b0,b1,b2,b3,b4,b5,b6,b7)
{
UserOutput (b0);
UserOutput (b1);
UserOutput (b2);
UserOutput (b3);
UserOutput (b4);
UserOutput (b5);
UserOutput (b6);
UserOutput (b7);
}
|
|
|
|
|
--------------------
var o = new array()
for(i=0;i<10;i++)
o[i]=i;
InputArray(o);
--------------------
I need to process the array from JavaScript in the MFC part.
I've tried many ways without results, I think I want your help badly now.
|
|
|
|
|
Dynamic creat a CCommandButton "btnGo2"
javascript is work
vbscript is not work
why?
script:
js
function btnGo2::Click()
{
display ("btnGo2:is work - javascript")
}
vbs
sub btnGo2_Click()
display "btnGo2:is work - vbscript"
end sub
thanks a lot.
modified on Monday, September 22, 2008 8:25 PM
|
|
|
|
|
In ActiveScriptHost.cpp (CActiveScriptHost::AddScriptCode)
Uncomment these lines:
hr = m_pAxsScript->SetScriptState(SCRIPTSTATE_CONNECTED);
HRESULT_EXCEPTION::CheckError( hr );
As for your script, I've used btnGo_Click instead. I noticed you are creating the second button manually, you may need to serialize some other properties as well.
In the end, we will remember not the words of our enemies, but the silence of our friends. - Martin Luther King Jr.
Ernest Laurentin
|
|
|
|
|
Hi,thanks for your reply
In the project
I find you mention the code and modify it (CActiveScriptHost::AddScriptCode)
When I add the button "btnGo2" , the program not throw any exception
Vbs event still does not work , but other codes work (such as for... ,ScriptHost_OnRun(),if...else...)
JS event work normally.
I don't know what the meaning of "serialize some other properties"
can you give an example?
|
|
|
|
|
When you add an ActiveX control from the dialog editor, Visual Studio will automatically set several properties for you. In your case since you create this manually, you may have to set them. In any case, it is much easier to drop the control in your dialog. Serialize, it's storing the property value as resource data. You can see them if you look at the .rc file.
In the end, we will remember not the words of our enemies, but the silence of our friends. - Martin Luther King Jr.
Ernest Laurentin
|
|
|
|
|
thank you very much
I learn more now
I'll try to do it.
|
|
|
|
|
Hi,
I guess it's vbs's bug, it only support one button.the first "AddScriptItem" button can work.
I test it two ways
1.In CMFCScriptHostDlg::OnInitDialog()
create button("btnGo2") manually and AddScriptItem(L"btnGo2",...) before the old button "btnGo"
so the "btnGo2" work and "btnGo" not work;
2.add another button("btnGo3") in dialog resource editor
"AddScriptItem" before the old button "btnGo" in CMFCScriptHostDlg::OnInitDialog()
so the "btnGo3" work and "btnGo" not work;
Create two ScriptProxy can support two button,but not a good solution.
At last ,I only change the AddScriptItem(L"btnGo",...) after AddScriptItem( L"txtAddress",..) ,the "btnGo" not work ,so I know the button must add at first and only one .
m_ScriptProxy.CreateEngine( L"VBScript" );
LPDISPATCH pDispatch = NULL;
LPUNKNOWN pUnkControl ;
pUnkControl = m_txtAddress.GetControlUnknown();
ASSERT( pUnkControl != NULL );
if (pUnkControl != NULL)
m_ScriptProxy.AddScriptItem( L"txtAddress", pUnkControl);
pUnkControl = m_btnGo.GetControlUnknown();
ASSERT( pUnkControl != NULL );
if (pUnkControl != NULL)
m_ScriptProxy.AddScriptItem( L"btnGo", pUnkControl);
pUnkControl = m_webBrowser.GetControlUnknown();
ASSERT( pUnkControl != NULL );
if (pUnkControl != NULL)
m_ScriptProxy.AddScriptItem( L"webBrowser", pUnkControl);
m_webBrowser.GoHome();
I test other control such as combobox .... ,
same as button ,only one control's event can work when I use vbs.
but it work nomarlly when I use js.
best regards
modified on Friday, September 19, 2008 8:52 AM
|
|
|
|
|
|
In CActiveScriptHost::AddScriptItem : make sure you comment these lines:
In CActiveScriptHost::AddScriptCode , as I indicated in previous post you need to uncomment these:
hr = m_pAxsScript->SetScriptState(SCRIPTSTATE_CONNECTED);
HRESULT_EXCEPTION::CheckError( hr );
Hope that helps!
In the end, we will remember not the words of our enemies, but the silence of our friends. - Martin Luther King Jr.
Ernest Laurentin
|
|
|
|
|
thank for your help!
it's a excellent job
hope keep in touch.
Best regards.
modified on Monday, September 22, 2008 8:24 PM
|
|
|
|
|
Your javascript code run sucessfully
function btnGo::Click()
{
var sUrl = txtAddress.Text;
webBrowser.Navigate( sUrl );
}
function webBrowser::NavigateError(pDisp, sUrl, pFrame, bCancel)
{
ScriptHost.Display("Failed to navigate: " + sUrl );
ScriptHost.QuitApp();
}
function webBrowser::NavigateComplete2(pDisp, sUrl)
{
ScriptHost.Display("Viewing: " + sUrl );
}
function ScriptHost::OnRun()
{
Display("Started...");
}
function ScriptHost::OnAppExit()
{
Display("Exiting...");
}
I rewrite the code by vbscript
function btnGo_Click()
dim sUrl
sUrl = txtAddress.Text
webBrowser.Navigate sUrl
end function
function webBrowser_NavigateError(pDisp, sUrl, pFrame, bCancel)
ScriptHost.Display ("Failed to navigate: " & sUrl )
ScriptHost.QuitApp()
end function
function webBrowser_NavigateComplete2(pDisp, sUrl)
ScriptHost.Display ("Viewing: " & sUrl )
end function
function ScriptHost_OnRun()
Display("Started...")
end function
function ScriptHost_OnAppExit()
Display("Exiting...")
end function
the button click run sucessfully but the webBrowser NavigateComplete2 event not run. why?
thank you
best regards.
|
|
|
|
|
Hi,
I supposed this is an enhanced security settings for IE. I was using old IE ActiveX or try changing your security settings (not recommended).
The ScriptHost_OnRun and btnGo work
BTW: I've used the following code
Sub btnGo_Click()
dim sUrl
sUrl = txtAddress.Text
webBrowser.Navigate sUrl
End Sub
Sub webBrowser_NavigateError(pDisp, sUrl, pFrame, bCancel)
ScriptHost.Display ("Failed to navigate: " & sUrl )
ScriptHost.QuitApp
End Sub
Sub webBrowser_NavigateComplete2(pDisp, sUrl)
ScriptHost.Display "Viewing: " & sUrl
End Sub
Sub ScriptHost_OnRun()
Display("Started...")
End Sub
Sub ScriptHost_OnAppExit()
Display("Exiting...")
End Sub
God bless,
Ernest Laurentin
|
|
|
|
|
Hi,
I try to get return or mofified argument from event function like 'OnRun'.
funtion OnRun ()
{
return 1;
}
or
// Value => VTS_PI4
function OnRun ( Value )
{
Value = 5;
}
But it don't work ?
Do you have a solution ?
thanks,
Arnaud
...
|
|
|
|
|
Arnaud,
I don't think it's a good idea to use 'OnRun' for that purpose. 'OnRun' is an event-handler and has no return value. Your second example is not entire correct since your parameter is passed by value not reference. It's possible to get return values but don't use event-handler for that purpose.
Cheers-
God bless,
Ernest Laurentin
|
|
|
|
|
Hi,
I test ref at the begin but in JScript it don't work...
I solve this problem by adding a new method that can be call by script to set a global error code. After script function call, i call a function like "GetLasteErrorCode" on c++ to get it...
It's not really clean but it work...
Thank for your answer,
Bye...
...
|
|
|
|
|
Hi, I did a lot of search before posting this message and I would really appreciate your response!
How can I limit creation/usage of certain activex objects. E.g. in your sample app I can create Scripting.FileSystemObject and use, is there a way to restrict use of this object?
Also, is it possible to get a list of all activex objects being used in the script ahead of running the script?
|
|
|
|
|
You can intercept the call inside of 'CreateActiveX' object in the proxy class. To get a list of ActiveX object, you will have to write new method to return list of named item. Look at 'AddScriptItem' function. Basically, you need to write a function to loop through the map.
___________________
Ernest L.
- In God, I trust!
|
|
|
|
|
I have implemented a test object which i can access from the script. However
when there are errors, I'd like to give the user information about what failed.
So i Use AtlReportError(...), to my surprise the description never reaches the
scripthost.
What am i doing wrong. Is it enought to use AtlReportError(...)?
return AtlReportError(GetObjectCLSID(),"That was totally unexpected!",__uuidof(IMyInterface),E_UNEXPECTED);
Tom.
|
|
|
|
|