Steps to Reproduce Behavior
- Create a new MFC SDI application using AppWizard.
- Add the Microsoft Scriptlet Component to your Project from the Project |
Add to Project | Components and Controls menu. Choose "Microsoft
Scriptlet Component" from the "Registered ActiveX Controls" folder.
This will insert a class named CWebBridge.
- Include WebBridge.h into your view class header file with the following line:
- Declare an instance of CWebBridge in your view class like this:
- In the implementation of your view class's OnInitialUpdate, create the component like this:
CRect rc;
m_webBridge.Create(NULL, WS_VISIBLE|WS_CHILD, rc, this,
IDC_WEBBRIDGE);
- Open resource.h from your program's directory and add the following:
#define IDC_WEBBRIDGE 500
- Compile and run your application.
When you run your application you will receive the assertion described in
the SUMMARY section of this article.
Workaround
In order to work around this problem, you can use the #import command to
create smart pointer classes for the Microsoft Scriptlet Component. Then
you can use this component as you normally would. The following are the
steps to follow in order to implement this solution in your code:
- Import the Microsoft Scriptlet Component in-proc server DLL into your
project by placing the following code in the header file for your view
class or in stdafx.h:
#import <mshtmlwb.dll> // This DLL should be in your system dir
using namespace WBLib;
#include <comdef.h> // Needed for Compiler COM support
- Declare an instance of IWebBridgePtr in your view class. IWebBridgePtr is a smart pointer for the IWebBridge interface:
IWebBridgePtr m_webBridge;
- Initialize COM using CoInitialize. You may want to do this in the
constructor for your view class or in OnInitialUpdate:
- Create and instance of the Scriptlet Component in OnInitialUpdate.
void CMyView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// Create an instance of the Scriptlet Component.
// Here, I am asking for a pointer to the IWebBridge interface.
// You could ask for IWBScriptControl or query for it later.
HRESULT hr = CoCreateInstance(_uuidof(Scriptlet), NULL,
CLSCTX_INPROC_SERVER,
_uuidof(IWebBridge),
(void**)&m_webBridge);
if (SUCCEEDED(hr))
{
// Insert some code here
}
}
- Use the Scriptlet Component like normal. For example, if you want to
find out if scrollbars are on or off, you would use this code:
BOOL bScrollbar;
bScrollbar = m_webBridge->GetScrollbar();
TRACE("Scrollbar is %s\n", bScrollbar ? "on" : "off");