Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Windows Script Host

Windows Script Host

Scheduled Pinned Locked Moved C / C++ / MFC
toolstestinghelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    soup
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • S soup

      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

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups