FIX: ScriptControl Reports Invalid Language for VBScript in MFCID: Q184977
|
When hosting the ScriptControl object in a MFC application, you may receive the following error:
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 JavaScript as the language for the ScriptControl Object.The operation could not be completed because the script engine has not been initialized to a valid language.
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:
// 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"
void CScrptctrlView::OnInitialUpdate()
{
CView::OnInitialUpdate();
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 bstrLanguage(L"VBScript");
_bstr_t bstrCode(L"MsgBox \"Hello World\"");
// Create the Script Control, initialize Language, and
// add code for processing.
IScriptControlPtr spScriptCtl(__uuidof(ScriptControl));
spScriptCtl->put_Language(bstrLanguage);
spScriptCtl->AddCode(bstrCode);
}
catch(_com_error e)
{
TRACE(_T("Error (%08x) in %s: %s\n"), e.Error(),
e.Source(), e.Description());
}
}
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Microsoft Internet Explorer 5.
// 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"
void CScrptctrlView::OnInitialUpdate()
{
CView::OnInitialUpdate();
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 bstrLanguage(L"VBScript");
_bstr_t bstrCode(L"MsgBox \"Hello World\"");
// Create the Script Control, initialize Language, and
// add code for processing.
IScriptControlPtr spScriptCtl(__uuidof(ScriptControl));
spScriptCtl->put_Language(bstrLanguage);
spScriptCtl->AddCode(bstrCode);
}
catch(_com_error e)
{
TRACE(_T("Error (%08x) in %s: %s\n"), e.Error(),
e.Source(), e.Description());
}
}
For additional information, please see the following article(s) in the Microsoft Knowledge Base:
Q184904 FILE: MSSCPCTL.EXE Script Control Header File MSSCPCTL.HFor additional information, please see the following World Wide Web URL:
http://msdn.microsoft.com/scripting/
Additional query words: ScriptControl Script Control kbScript
Keywords : kbIE500fix
Version : WINDOWS:3.0; winnt:5.0
Platform : WINDOWS winnt
Issue type : kbbug
Last Reviewed: May 27, 1999