SUMMARY
This article explains how to use CreateObject with COM/ActiveX components
created in Visual C++. The CreateObject programming syntax used to create
an instance of a component created in Visual Basic may not work with a VC++
component, even though the object can be created using the New method. For
example, assume you have an component named "neuLib" referenced in a Visual
Basic project. The component has one createable object (Interface) named
"myclass." The following code will work if the ActiveX component was
created using either Visual Basic or Visual C++:
Dim objNeu as neuLib.myclass
Set objNeu = New neuLib.myclass
However, the code below will work only for a component created using Visual
Basic:
Dim objNeu as neuLib.myclass
Set objNeu = CreateObject("neuLib.myclass")
If this is a VC++-created component, you will receive the error message:
"Error 429. ActiveX component can't create object."
The reason CreateObject works with a Visual Basic component and not with a
Visual C++ component can be explained and resolved by examining the
different way in which Visual Basic and Visual C++ create program IDs
(ProgID.) When you use CreateObject, the argument you provide is a ProgID.
Visual Basic and Visual C++ assign a name to the ProgID differently.
Visual Basic uses the original name, Visual C++ does not. In a Visual Basic
component, the ProgID for this example is "neuLib.myclass." In a Visual C++
component, the ProgID would be "myclass.myclass.1," which requires the
(correct) syntax:
Dim objNeu as neuLib.myclass
Set objNeu = CreateObject("myclass.myclass.1")