PRB: VB References Dialog Box Does Not List an MFC DLL Automation Server (219261)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 5.0
- Microsoft Visual C++, 32-bit Editions 6.0
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q219261 SYMPTOMS
When you first build an MFC DLL automation server, the Microsoft Visual Basic References dialog box fails to display it until you browse and select the server manually.
CAUSE
Visual Basic looks for the type library of the automation server to be registered. In the case of an MFC DLL automation server, Visual Basic does not register it by default. Once you browse and select the server DLL, Visual Basic registers the type library and thereafter it will be listed by the References dialog box.
RESOLUTION
Add code to the server to register the Type library along with the server registration. Use the following steps to add the Type library registration code. - In your Microsoft Visual C++ project, go to the FileView and right-click on the ODL file and select Settings. In the text box that says UUID File, type in the file name. For example, if the ODL file is Test.odl, name the file Test_i.c. Also, in the Output header file name box, enter the corresponding header file name, for example, Test_i.h.
- Click OK and compile the ODL file. This generates the Test_i.c and Test_i.h files in the current project directory.
- Go to the function DllRegisterServer. If the project name is Test, this will be in Test.cpp file.
- Add the following code to the function:
// by exporting DllRegisterServer, you can use regsvr.exe
STDAPI DllRegisterServer(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
COleObjectFactory::UpdateRegistryAll();
// Add this line to register the typelib
AfxOleRegisterTypeLib(AfxGetInstanceHandle(), LIBID_Test);
return S_OK;
}
- Add the following two #includes to the top of Test.cpp file. LIBID_Test is defined in the Test_i.c file.
#include "Test_i.h"
#include "Test_i.c"
Also you would need to do a
#include <afxctl.h>
to your Stdafx.h file. This is where "AfxOleRegisterTypeLib" is declared. - Compile and run regsvr32 on the server. This registers the typelib information also and the Visual Basic reference box shows it without any effort.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 12/2/2003 |
---|
Keywords: | kbAutomation kbprb KB219261 |
---|
|