Microsoft KB Archive/224185

= FIX: User Defined Type in Public Function of a User Control Fails to Run =

Article ID: 224185

Article Last Modified on 8/7/2007

-

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 Q224185



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. When this User control is used in other Microsoft Visual Basic projects, it does not run on any machine other than the development machine. When deployed to other machines, the application just beeps and exits.



CAUSE
The CLISID of the OCA file is being used in the executable 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 the User control 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. This bug was corrected in the next service pack for Visual Studio 6.0.

For additional information about Visual Studio service packs, click the following article numbers to view the articles in the Microsoft Knowledge Base:

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

194295 HOWTO: Tell That a Visual Studio Service Pack Is Installed

To download the latest Visual Studio service pack, visit the following Microsoft Web site:

http://msdn2.microsoft.com/en-us/vstudio/Aa718353.aspx



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 udtControl . On the File menu, select Make Project1.ocx to compile the control, and then name it udtControl.OCX . From the Project properties, select the Component tab, and set the Binary Compatibility to udtControl.OCX .</li> From the File menu, select Add Project, and create a new Visual Basic Standard EXE project. Form1 is created by default.</li> Make sure the UserControl design window is closed, and then site an instance of udtControl.OCX on Form1.</li>  Add the following code to the General Declarations section of Form1: Private Sub Form_Load Dim myUdt As UdtType myUdt = UserControl11.udtFunction MsgBox myUdt.strHello End Sub </li> From the File menu, select Make Project2.exe to compile the executable.</li> Run the Package and Deployment Wizard (PDW) to create a new Package. Install this Package onto another machine.</li> Run the EXE on the target machine and note that you hear a beep and the application terminates without displaying the form.</li></ol>

<div class="references_section">