正常にコンパイルできますが、プログラムを実行しようとすると、DLL が存在しないというエラーがスローされます。試行錯誤の結果、プログラムは「ROGRAM FILES\FolderName\rrpd.dll」で DLL を探していて、明らかにフォルダーの最初の 4 文字を切り捨てていることがわかりました。
これは、R&R Report Writer と呼ばれるアプリケーションで、25 年以上使用されており、これまでこの問題が発生したことはありません。
デバッグ中、プログラム モジュール EXPLMGR.CPP (明示的なライブラリ マネージャー) の代入ステートメントからエラーが発生していると判断しました。
CString CExplicitLibraryManager::FindLocalDllFile(CString csDllName) const
{
ASSERT( csDllName.Find('\\') == -1 ); // These names should not have directory stuff.
// Search for the file in the program directory directory.
// If not found there, search in the registry system.
// If not found in either location, just return the file name.
CString csDllPath = m_csAppDirectory + csDllName ;
BOOL bDllExists = DoesFileExist ( csDllPath ) ; // Don't bother calling DoesDllExist(). A path is provided.
if ( !bDllExists )
{
csDllPath = m_csRrSystemDirectory + csDllName ;
bDllExists = DoesFileExist ( csDllPath ) ;
if ( !bDllExists )
{
// Must call the FindWindowsFile() here so that we can guarentee to return the full pathname.
csDllPath = FindWindowsFile ( csDllName ) ;
bDllExists = DoesFileExist ( csDllPath ) ;
}
}
if ( bDllExists )
{
CFileStatus fsFile ;
CFile::GetStatus ( csDllPath, fsFile ) ;
//TRACE( "CExplicitLibraryManager::FindLocalDllFile() Reports the DLL to be %s\n", fsFile.m_szFullName ) ;
csDllPath = fsFile.m_szFullName ;
}
return csDllPath ;
}
具体的には、下から 4 行目:
csDllPath = fsFile.m_szFullName ;
この時点で、fsFile.m_szFullName は「C:\PROGRAM FILES\FolderName\rrpd.dll」、csDllPath も同じものです。
デバッグして[F11]を押すと、割り当てがすぐに飛び込みます
c:\program files\Microsoft visual studio\vc98\mfc\src\strcore.cpp
セクションは次のとおりです。
const CString& CString::operator=(LPCTSTR lpsz)
{
ASSERT(lpsz == NULL || AfxIsValidString(lpsz));
AssignCopy(SafeStrlen(lpsz), lpsz);
return *this;
}
そしてすぐに、lpsz にマウスを合わせると、その値は現在
"rogram files\FolderName\rrpd.dll"
これに対処する方法はありますか?どのような追加情報を提供できますか?