How to Register an MFC OLE Automation Server to Avoid Failure (137516)



The information in this article applies to:

  • The AppWizard, when used with:
    • Microsoft Visual C++, 32-bit Editions 2.0
    • Microsoft Visual C++, 32-bit Editions 2.1
    • Microsoft Visual C++, 32-bit Editions 2.2

This article was previously published under Q137516

SUMMARY

Creation of an OLE Object may fail if the registry file (.reg) generated by AppWizard is used to register the server for the object. This article explains how to avoid this failure.

MORE INFORMATION

Registration of an MFC OLE Automation server typically occurs when running the server stand-alone for the first time. An alternate way of registering the server is to run the registration editor and merge the .reg file generated by AppWizard for the server's project. This method is necessary if the server is installed but not run before a client tries to create it.

It is necessary that the setup program that installs the server also replace any occurrence of the executable in the .reg file with the fully- qualified path and file name of the executable. When AppWizard creates the .reg file for the project, AppWizard does not know what the final path to the executable will be. Therefore, AppWizard cannot fill in the fully qualified path name for the server.

If the .reg file provided by the AppWizard is used as is to register the server for an object, OLE won't be able to find the server, creation of the object will fail, and OLE will return the error CO_E_SERVER_EXEC_FAILURE.

Sample Code

The following is an example of the \LocalServer key for the AutoClik, Step 1 sample as generated by AppWizard:
HKEY_CLASSES_ROOT\CLSID\{2106E720-AEF8-101A-
     9005-00DD0108D651}\LocalServer = AUTOCLIK.EXE
				
After being setup correctly, the \LocalServer key in the .reg file may appear as follows:
HKEY_CLASSES_ROOT\CLSID\{2106E720-AEF8-101A-
     9005-00DD0108D651}\LocalServer = C:\MSVC20\SAMPLES\MFC
                         \autoclik\step3\WinDebug\AUTOCLIK.EXE
				

Modification Type:MajorLast Reviewed:10/24/2003
Keywords:KB137516