Possible Reasons for OLE Control Registration Failure

Αποποίηση ευθυνών για περιεχόμενο της Γνωσιακής βάσης που έχει αποσυρθεί

Αυτό το άρθρο αφορά προϊόντα για τα οποία η Microsoft δεν παρέχει πλέον υποστήριξη. Συνεπώς, το παρόν άρθρο παρέχεται "ως έχει" και δεν θα ενημερώνεται πλέον.

Summary

OLE controls can be registered by using Visual C++ from the Tools menu, from the Test Container provided with the Control Development Kit (CDK), or by using the regsvr or regsvr32 applications provided with Visual C++. In some cases, the registration of a control may fail; use this article to help troubleshoot the problem.

More Information

All of the previously mentioned methods for registering an OLE Control use essentially the same technique. LoadLibrary() is called to load the control into memory, GetProcAddress() is called to get the address of the DllRegisterServer() function, and then DllRegisterServer() is called to register the control.

Reasons Why the Registration of a Control May Fail

  • One or more of the necessary OLE DLLs is not in the path. Instructions for distributing OLE Controls as well as an explanation of what DLLs are necessary to ship can be found in the Shipctrl.wri file located in the same directory as the CDK.
  • The control is loading a DLL other than the OLE DLL, and that DLL is not in the path. When the control is loaded into memory, any DLLs that are implicitly loaded through an import library are also loaded. If any of these DLLs are not in the path, the control is not loaded successfully, so registration fails.
  • One or more DLLs may be the wrong version. If the control was built with a newer version of a DLL than the one installed on the computer, the control may not load properly, so registration fails.
  • An old version of Ocd25.lib is being linked to. If the control is using the MFC database classes, there may be a problem with the version of the Ocd25.lib file that is being linked to.
  • The OLE control is located on a Novell server's remote drive. In this case, the access rights to the .ocx file may be preventing the control from loading. Make sure that the access rights for the .ocx file are set to read-only, shareable access, which is the typical setting for executable files.

Troubleshooting Techniques

If none of the possible causes are true in your case, try the following techniques.


  1. With the control project loaded in Visual C++, set the executable for the debug session to the OLE Control Test Container (Tstcon16.exe or Tstcon32.exe). When you start the Test Container (under the debugger), you will get a warning that the Test Container does not contain debug information. Ignore this and proceed.
  2. From the Test Container, attempt to register the control. Watch for debug output from the OLE Control DLL or any of its dependent DLLs. If you are running the 16-bit product, remember to run the DBWIN program to receive debug output.


    For information on how to set the executable for a DLL debug session, please see the help topic "Debugging DLLs" in Books Online.
As an alternative, you can attempt to register the control programmatically. First create an MFC AppWizard application selecting Dialog-based application and OLE Automation. Enabling OLE Automation will initialize OLE so that the code to register the control will work properly. In the CWinApp-derived class, you will find the function InitInstance() with the initial code as follows:

BOOL CTestregApp::InitInstance()
{

// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
At this point, add the following code segment, which will allow you to check the return codes from LoadLibrary(), GetProcAddress(), and DllRegisterServer.

#ifdef _WIN32
HINSTANCE hDLL = LoadLibrary("some.ocx");
if(NULL == hDLL)
{
// See Winerror.h for explaination of error code.
DWORD error = GetLastError();
TRACE1("LoadLibrary() Failed with: %i\n", error);
return FALSE;
}

typedef HRESULT (CALLBACK *HCRET)(void);
HCRET lpfnDllRegisterServer;

lpfnDllRegisterServer =
(HCRET)GetProcAddress(hDLL, "DllRegisterServer");
if(NULL == lpfnDllRegisterServer)
{
// See Winerror.h for explaination of error code.
DWORD error = GetLastError();
TRACE1("GetProcAddress() Failed with %i\n", error);
return FALSE;
}

if(FAILED((*lpfnDllRegisterServer)()))
{
TRACE("DLLRegisterServer() Failed");
return FALSE;
}

#else // 16-bit
HINSTANCE hDLL = LoadLibrary("regtest.ocx");
if(HINSTANCE_ERROR > hDLL)
{
// See LoadLibrary() help for explaination of error code.
TRACE1("LoadLibrary() Failed with: %i\n", hDLL);
return FALSE;
}

typedef HRESULT (CALLBACK *HCRET)(void);
HCRET lpfnDllRegisterServer;

lpfnDllRegisterServer =
(HCRET)GetProcAddress(hDLL, "DllRegisterServer");
if(NULL == lpfnDllRegisterServer)
{
// See GetProcAddress() help for explaination of error code.
TRACE("GetProcAddress() Failed");
return FALSE;
}

if(FAILED((*lpfnDllRegisterServer)()))
{
TRACE("DLLRegisterServer() Failed");
return FALSE;
}
#endif
Ιδιότητες

Αναγνωριστικό άρθρου: 140346 - Τελευταία αναθεώρηση: 1 Δεκ 2003 - Αναθεώρηση: 1

Σχόλια