How to call a script method from an ActiveX script host in Visual C++

Article translations Article translations
Article ID: 222966 - View products that this article applies to.
This article was previously published under Q222966
This article has been archived. It is offered "as is" and will no longer be updated.
Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model.
Expand all | Collapse all

On This Page

SUMMARY

This article describes how to call a method running inside an ActiveX Scripting engine, such as Visual Basic Script or Java Script, from an ActiveX Scripting host.

MORE INFORMATION

Follow these steps to call a method running inside an ActiveX Scripting engine from its ActiveX Scripting host:

Step-by-Step Procedures

  1. After creating and initializing the ActiveX Scripting engine, add the method by calling IActiveScriptParse::ParseScriptText as follows:
    HRESULT IActiveScriptParse::ParseScriptText( LPCOLESTR pstrCode, 
       LPCOLESTR pstrItemName, IUnknown *punkContext, 
       LPCOLESTR pstrDelimiter, DWORD dwSourceContextCookie,
       ULONG ulStartingLineNumber, DWORD dwFlags, VARIANT *pvarResult,
       EXCEPINFO *pexcepinfo );
    						
  2. The ActiveX Scripting engine starts with a call to the IActiveScript::SetScriptState method, passing either the SCRIPTSTATE_STARTED or SCRIPTSTATE_CONNECTED flag.
  3. When you want to call the script method from your ActiveX Scripting host, call IActiveScript::GetScriptDispatch to get an IDispatch pointer, which you can use to call the method. Pass as the pstrItemName, which is the same value you passed in the pstrItemName parameter of ParseScriptText. If you left pstrItemName NULL in your call to ParseScriptText, leave it NULL here as well. This will retrieve an IDispatch pointer to all the global methods in the ActiveX Scripting engine. Pass the address of an IDispatch pointer as the second parameter as follows:
    HRESULT IActiveScriptParse::GetScriptDispatch( LPCOLESTR lptrItemName, 
       IDispatch **ppdisp );
    						
  4. If the call to GetScriptDispatch succeeds, you can use the IDispatch pointer that you passed to call your script method. Call IDispatch::GetIDsOfNames to get a DISPID for the method you want to call. Use that DISPID to make a call to IDispatch::Invoke.

REFERENCES


For more information, click the following article number to view the article in the Microsoft Knowledge Base:
168214 Sample: MFXAxs Implements an ActiveX Script Host Using MFC.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
183698 Sample: AXSH.EXE Demonstrates Implementing ActiveX Script Hosts.

Properties

Article ID: 222966 - Last Review: February 21, 2014 - Revision: 5.0
APPLIES TO
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
Keywords: 
kbnosurvey kbarchive kbhowto kbactivexscript KB222966

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com