Microsoft KB Archive/190686

= ATL server registration may fail if you logged on by using an account that does not have appropriate registry user rights =

Article ID: 190686

Article Last Modified on 9/1/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 2.1, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 5.0 Professional Edition

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li> Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q190686

<div class="symptoms_section">

SYMPTOMS
Registration or unregistration of ATL servers may fail on a machine if the logged-on user doesn't have appropriate registry user rights. In-process servers may fail and display the following message:

DllRegisterServer in projectname.dll failed. Return code was:

0x80020009.

Debug EXE servers, linked statically to the registrar code and run in the debugger, may display the following trace messages:

Failed to register, cleaning up!

The thread 0xnn has exited with code -2147352567 (0x80020009).

<div class="cause_section">

CAUSE
CRegKey is a class used by ATL for manipulating the registry. It's Open and Create methods have a REGSAM argument that specifies the security access to the particular registry key.

The REGSAM argument defaults to KEY_ALL_ACCESS. In several places in the ATL code, Open and Create are called without specifying the REGSAM, which means it defaults to KEY_ALL_ACCESS. KEY_ALL_ACCESS is a combination of other flags including WRITE_DAC and WRITE_OWNER.

For a nonadministrator, you may not have WRITE_DAC and WRITE_OWNER permissions, which causes registration to fail.

<div class="resolution_section">

RESOLUTION
In ATLBASE.H, change the default REGSAM for CRegKey::Create and CRegKey::Open to KEY_READ|KEY_WRITE: class CRegKey {     ...      LONG Create(HKEY hKeyParent, LPCTSTR lpszKeyName, LPTSTR lpszClass =         REG_NONE, DWORD dwOptions = REG_OPTION_NON_VOLATILE,         REGSAM samDesired = KEY_READ | KEY_WRITE, // changed REGSAM         LPSECURITY_ATTRIBUTES lpSecAttr = NULL,         LPDWORD lpdwDisposition = NULL); LONG Open(HKEY hKeyParent, LPCTSTR lpszKeyName,        REGSAM samDesired = KEY_READ | KEY_WRITE);  // changed REGSAM ...  }; You need to link statically to the registrar. Building for ReleaseMinDependency will statically link to the registrar. Debug builds link dynamically to the registrar via Atl.dll. You need to add _ATL_STATIC_REGISTRY to the list of Preprocessor definitions. You can do this on the Project menu by clicking Settings. Click the C/C++ tab and select General under Category.

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

166717 Instructions for statically linking to registrar code

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section. This problem was corrected in Microsoft Visual C++ .NET.

<div class="references_section">