When hosting the ScriptControl object in a MFC application, you may receive
the following error:
The operation could not be completed because the script engine has not
been initialized to a valid language.
This occurs even though you previously set the language to VBScript using
the SetLanguage method. This error does not occur if you specify JScript or
When hosted as a control (and not just as a simple automation object), the
ScriptControl object fails to initialize itself properly if the specified
language is VBScript.
Here are two workarounds:
- Clear the language before setting it:
Add a call to ScriptControl::SetLanguage(NULL) right before calling
- Automating the ScriptControl object:
Alternatively, applications that use the ScriptControl can switch to
automating the Script Control just as an automation object rather than
as a full-blown control. This has the advantage of resolving the bug
indicated by this article as well as improving performance. The client
application does not need to go through the overhead of the ActiveX
control hosting negotiation, which is essentially unnecessary for the
non-UI Script Control.
Below is a piece of sample code that uses Visual C++ 5.0 COM support to
easily CoCreateInstance the ScriptControl and activate it.
// Import Type Info from Script OCX - point path to the
// location of the Script Control on your development computer.
#import "C:\Program Files\Microsoft Script Control\msscript.ocx"
OleInitialize(NULL); // Only if you haven't done this already
// or called AfxOleInit.
using namespace MSScriptControl;
try // Make sure exception handling is turned on.
_bstr_t bstrCode(L"MsgBox \"Hello World\"");
// Create the Script Control, initialize Language, and
// add code for processing.
TRACE(_T("Error (%08x) in %s: %s\n"), e.Error(),
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Microsoft Internet Explorer 5.
For additional information, please see the following
article(s) in the Microsoft Knowledge Base:
FILE: MSSCPCTL.EXE Script Control Header File MSSCPCTL.H
For additional information, please see the following World Wide Web URL: