Dispatch Interface for Automation Object Must Be RegisteredID: Q154664
|
Visual Basic 4.0 can do typesafe binding to automation objects. In this scenario, the Visual Basic program will QueryInterface the automation object for its dispatch interface. If the interface is not registered on the machine, the Visual Basic program will fail to create the object. In this case, Visual Basic will report the following error:
Error 430: Class Does not Support OLE Automation.
Visual Basic does typesafe binding to an automation object when a variable is dimensioned as a specific type. For instance:
When developing this code, establish a reference to the TestVB module (in the Visual Basic development environment, select Tools, References, and Browse for the TestVB type library). Select the type library to register the type library and the dispatch interface for the Document object.Dim x As New TestVB.Document
// Note: We add support for IID_ITestVB to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {1249A4D2-D469-11CF-A68F-00AA00A70FC2}
static const IID IID_ITestVB =
{ 0x1249a4d2, 0xd469, 0x11cf,
{ 0xa6, 0x8f, 0x0, 0xaa, 0x0, 0xa7, 0xf, 0xc2 } };
BEGIN_INTERFACE_MAP(CTestVBDoc, CDocument)
INTERFACE_PART(CTestVBDoc, IID_ITestVB, Dispatch)
END_INTERFACE_MAP()
The following .reg file will register the ITestVB interface and enable
marshaling of the interface via the standard IDispatch proxy and stub.
REGEDIT
HKEY_CLASSES_ROOT\Interface\{1249A4D2-D469-11CF-A68F-00AA00A70FC2}
= ITestVB
HKEY_CLASSES_ROOT\Interface\{1249A4D2-D469-11CF-A68F-00AA00A70FC2}
ProxyStubClsid = {00020420-0000-0000-C000-000000000046}
HKEY_CLASSES_ROOT\Interface\{1249A4D2-D469-11CF-A68F-00AA00A70FC2}
ProxyStubClsid32 = {00020420-0000-0000-C000-000000000046}
To programmatically register the interface, #include <winreg.h>, and insert
the following code (with the proper dispatch ID) in the InitInstance of the
automation server:
HKEY key;
// Open HKEY_CLASSES_ROOT
RegOpenKey(HKEY_CLASSES_ROOT, _T("Interface"), &key);
// Set up the key
RegSetValue( key,
_T("{1249A4D2-D469-11CF-A68F-00AA00A70FC2}"), REG_SZ,
_T("ITestVB"), 0);
RegSetValue( key,
_T("{1249A4D2-D469-11CF-A68F-00AA00A70FC2}\\ProxyStubClsid"),
REG_SZ, _T("{00020420-0000-0000-C000-000000000046}"), 0);
RegSetValue( key,
_T("{1249A4D2-D469-11CF-A68F-00AA00A70FC2}\\ProxyStubClsid32"),
REG_SZ, _T("{00020420-0000-0000-C000-000000000046}"), 0);
RegCloseKey(key);
Additional query words: Automation 430
Keywords : kbole kbMFC kbVC
Version : Winnet:4.0,4.1,4.2
Platform : NT WINDOWS
Issue type : kbinfo
Last Reviewed: July 23, 1999