Windows Script Host
-
Hi, I am working on making my app a Windows Script Host. So far I have a class that entirely works. You might say why do I need help? Well, here's the thing. I can add an automation object to the engine so that I can have my own methods. But if I don't name the object in ParseScriptText (2nd parameter), it never finds the 'new' functions when I run the script. Therefore, I can make it work when there is one object (by naming it in ParseScriptText), but not if I have 2 or more since there is only one param. Do I have to call ParseScriptText in a loop for all added name objects to get more than one object to work with the engine? Thanks in advance, Simon
-
Hi, I am working on making my app a Windows Script Host. So far I have a class that entirely works. You might say why do I need help? Well, here's the thing. I can add an automation object to the engine so that I can have my own methods. But if I don't name the object in ParseScriptText (2nd parameter), it never finds the 'new' functions when I run the script. Therefore, I can make it work when there is one object (by naming it in ParseScriptText), but not if I have 2 or more since there is only one param. Do I have to call ParseScriptText in a loop for all added name objects to get more than one object to work with the engine? Thanks in advance, Simon
I think you need to look into using AddNamedItem which is part of IActiveScript. My code uses something like
void CLittleScript::ParseScript(LPCTSTR sScript)
{
EXCEPINFO ei;
_bstr_t bstrParseText(sScript);HRESULT hr = m\_iScriptParse->ParseScriptText(bstrParseText.copy(), NULL /\*L"MyApp"\*/, NULL,NULL,0,0,SCRIPTTEXT\_ISVISIBLE, NULL, &ei);
if(hr == S_OK)
{
hr = m_iScript->SetScriptState(SCRIPTSTATE_CONNECTED);
}
else
{
littleDebugger()->Error("Failed to Parse Script Text %x", hr);
}
}HRESULT CLittleScript::AddScriptObject(LPCSTR sObjectName, IUnknown* pObject)
{
m_ScriptSite.AddScriptObject(sObjectName, pObject);
HRESULT hr = m_iScript->AddNamedItem(_bstr_t(sObjectName),
SCRIPTITEM_ISVISIBLE | SCRIPTITEM_ISSOURCE);if(hr != S_OK)
{
littleDebugger()->Error("Failed to add named item %x", hr);
}return hr;
}In my ActiveScriptSite::GetItemInfo, I loop through for the required object interface.
if(dwReturnMask & SCRIPTINFO_IUNKNOWN)
{
for(int nLoop = 0; nLoop < m_collectionObjects.Count(); nLoop++)
{
SCRIPTOBJECT* pObject = m_collectionObjects.GetItem(nLoop);
if(pObject)
{
_bstr_t a(pObject->m_sName.c_str());if(!\_wcsicmp((const wchar\_t\*)a, pstrName)) { (\*ppunkItem) = pObject->m\_pObject; pObject->m\_pObject->AddRef(); break; } }
}
}Michael :-) Communication is the first step towards enlightenment.