| FILE: Using VBX Controls in AN _AFXDLL DLLID: Q104239 
 | 
There are two techniques for using VBX controls in a dialog box that
is created in a dynamic-link library (DLL) built with _AFXDLL
(Microsoft Foundation Class Library Extension DLL):
Afxvbx.exeFor more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
Q119591 How to Obtain Microsoft Support Files from Online Services
A dialog box template that uses VBX controls specifies "VBControl" as
the window class for each of the VBX controls. MFC registers the
"VBControl" class when a programmer calls EnableVBX(). This is
typically done in the InitInstance() function of a program. However,
the class is registered as a local class rather than a global class.
This means that a DLL used by the application does not see the
registered window class and when Windows tries to create a dialog box in a
DLL that uses the "VBControl" class, the dialog box creation will fail.
To register the "VBControl" class for the DLL, the following code can
be used:
   // Check to see if the class is already registered.
   if(::GetClassInfo(hInstDLL,"VBControl",&wndClass)==0)
    {
     // If not registered, get the class information from the
     // application. This assumes that the application has called
     // EnableVBX to register the VBControl class.
     VERIFY(::GetClassInfo(AfxGetInstanceHandle(),"VBControl",
                           &wndClass));
     wndClass.hInstance = hInstDLL; // Change the instance handle so
                                    // it is that of the DLL and not
                                    // the App.
     VERIFY(::RegisterClass(&wndClass));  // Register the class.
    } 
   // PLEASE NOTE: THIS CODE ONLY TO BE USED WITH
   // VISUAL C++ VERSION 1.0 (MFC VERSION 2.0)
   BOOL CVBXDialog::OnInitDialog()
   {
    HINSTANCE hOldInstance = _AfxGetAppData()->appCurrentInstanceHandle;
    _AfxGetAppData()->appCurrentInstanceHandle = hInstDLL;
    CDialog::OnInitDialog();
    _AfxGetAppData()->appCurrentInstanceHandle = hOldInstance;
    // Add your initialization code below.
    return TRUE;
   } Additional query words:
Keywords          : kbfile kbsample kb16bitonly kbMFC kbVBX kbVC 
Version           : 1.0 1.5
Platform          : WINDOWS 
Issue type        : Last Reviewed: July 29, 1999