Microsoft KB Archive/201318

= You receive a "The system cannot find the file specified" error message when you register an ATL server with a long name =

Article ID: 201318

Article Last Modified on 4/28/2005

-

APPLIES TO

 Microsoft ActiveX Template Library 3.0, when used with:  Microsoft Visual C++ 6.0 Enterprise Edition

 Microsoft Visual C++ 6.0 Professional Edition

 Microsoft Visual C++ 6.0 Standard Edition 

-

<div class="notice_section">

This article was previously published under Q201318

<div class="symptoms_section">

SYMPTOMS
Registering an ATL server that has a long file name or one that resides in a directory with a long path name, returns a 0x80070002 error:

The system cannot find the file specified.

For DLLs, this error is returned by Regsvr32.exe. For EXEs, the call to Module::RegisterServer (CComModule::RegisterServer) in _tWinMain returns this error.

<div class="cause_section">

CAUSE
ATL's registration code uses GetShortPathName to retrieve the short name of the file and uses the short name for registration. GetShortPathName fails if the file doesn't have a short file name. The default behavior in Windows NT, Windows 95, and Windows 98 is to automatically create short file names (8.3 format) for files with long names. You can turn this option off by using the "System Policy Editor" (Poledit.exe). Certain file systems also don't support creation of short names by default. ATL tries to use the invalid file name returned by GetShortPathName in a call to LoadLibraryEx, and fails with 0x80070002.

<div class="resolution_section">

RESOLUTION
When GetShortPathName is called in the ATL source, add code to check whether or not it succeeded. The following functions must be modified:
 * CComModule::UpdateRegistryFromResourceS(UINT...) - ATLBASE.H, line 4933.
 * CComModule::UpdateRegistryFromResourceS(LPCTSTR...) - ATLBASE.H, line 4965.
 * AtlModuleUpdateRegistryFromResourceD - ATLBASE.H, line 5896.

Change the following lines from: // Convert to short path to work around bug in Windows NT 4.0's CreateProcess. TCHAR szModuleShort[_MAX_PATH]; GetShortPathName(szModule, szModuleShort, _MAX_PATH); LPOLESTR pszModule = T2OLE(szModuleShort); to the following: // Convert to short path to work around bug in Windows NT 4.0's CreateProcess. TCHAR szModuleShort[_MAX_PATH]; int cbShortName = GetShortPathName(szModule, szModuleShort, _MAX_PATH); LPOLESTR pszModule; if (cbShortName == _MAX_PATH) return E_OUTOFMEMORY; pszModule = (cbShortName == 0||cbShortName == ERROR_INVALID_PARAMETER) \ ? T2OLE(szModule) : T2OLE(szModuleShort); In CComModule::RegisterClassHelper(ATLBASE.H, line 5044), change the following lines from: // Convert to short path to work around bug in Windows NT 4.0's CreateProcess. TCHAR szModuleShort[_MAX_PATH]; GetShortPathName(szModule, szModuleShort, _MAX_PATH); key.SetKeyValue(szLS32, szModuleShort); to the following: // Convert to short path to work around bug in Windows NT 4.0's CreateProcess. TCHAR szModuleShort[_MAX_PATH]; int cbShortName = GetShortPathName(szModule, szModuleShort, _MAX_PATH); if (cbShortName == _MAX_PATH) return E_OUTOFMEMORY; if (cbShortName == 0 || cbShortName == ERROR_INVALID_PARAMETER) key.SetKeyValue(szLS32, szModule); else key.SetKeyValue(szLS32, szModuleShort); These changes have no result if you build for ReleaseMinSize, because code in ATL.dll is used instead.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Visual Studio 6.0 Service Pack 3.

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

194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed

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

194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why

<div class="moreinformation_section">

MORE INFORMATION
ATL registers servers using the short file name to work around a bug in Windows NT's CreateProcess function.

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

179690 FIX: Launching COM Server with Long File Name Returns 0x80080005

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

173673 Windows NT Server Tools for Windows NT Workstation 4.0 Available

<div class="references_section">