Microsoft KB Archive/237922

= BUG: User Defined Type Referenced by User Control Raises "Class not registered" Error Message =

Article ID: 237922

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q237922



SYMPTOMS
A User control has a Public User Defined Type (UDT). The User control has a Public function that has the UDT in the function declaration as either an argument or the return type. This User control, Control A, is then referenced in another User control, Control B. Control B is used in a standard EXE and distributed to another computer. If a new Visual Basic project on the second computer references Control B, when Control B is instantiated on a form, the following error occurs:

Class not registered. Looking for object with CLSID: {...}



CAUSE
The CLISID of the OCA file for Control A is being used to reference the UDT. This is incorrect. The OCA file should only be used at design time.



RESOLUTION
Define all UDTs in a separate ActiveX DLL and reference this DLL in both User controls, Control A and Control B, and the Standard EXE project. When the Standard EXE project is distributed, the ActiveX DLL is distributed as well.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a new Visual Basic ActiveX Control project. UserControl1 is created by default.  Add the following code to the General Declarations section of UserControl1: Public Type UdtType strHello As String End Type

Public Function udtFunction As UdtType udtFunction.strHello = "Hello World" End Function  On the Project menu, select Project1 properties, and change the Project name to ControlA . From the File menu, select Make ControlA.ocx to compile the control. From the Project menu, select ControlA properties, select the Component tab, and set the Binary Compatibility to ControlA.OCX .</li> From the File menu, select Add Project, and create a new Visual Basic ActiveX Control project. UserControl1 is created by default.</li> Make sure that the ControlA design window is closed, and then site an instance of ControlA on UserControl1.</li>  Add a Command button and paste the following code into the code window of UserControl1: Private Sub Command1_Click Dim myUdtA As UdtType myUdtA.strHello = "Bye" myUdtA = UserControl11.udtFunction MsgBox myUdtA.strHello End Sub </li> On the Project menu, select Project2 properties, and change the Project name to ControlB .</li> From the File menu, select Make ControlB.ocx to compile the control.</li> From the Project menu, select ControlB properties, select the Component tab, and then set the Binary Compatibility to ControlB.ocx.</li> From the File menu, select Add Project, and start a new Visual Basic Standard EXE project. Form1 is created by default.</li> Make sure the UserControl design windows are closed and site an instance of ControlB on Form1.</li> From the File menu, select Make Project3.exe, and then compile the executable.</li> Run the Package and Deployment Wizard (PDW). Be sure to include both ControlA.ocx and ControlB.ocx. Install the application Package on another machine.</li> Start a new Visual Basic Standard EXE project on the new machine. Form1 is created by default.</li> On the Project menu, select Components, select ControlB, and then click OK.</li> Site an instance of ControlB on Form1 and note that the error mentioned in the "Symptoms" section occurs.</li></ol>

<div class="references_section">