赋值语句截断字符

3
我可以成功编译,但是当我运行程序时,它会抛出一个错误,告诉我一个DLL不存在。经过试错,我确定程序在寻找“ROGRAM FILES\FolderName\rrpd.dll”中的DLL,显然截断了文件夹的前四个字符。
这是一个名为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 ;
}

具体来说,从底部向上数第四行:
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"

有没有什么方法来解决这个问题?我可以提供哪些额外的信息?


1
我的第一个想法是重新构建所有内容,如果你还没有这样做的话。 - RichieHindle
1
就像 @RichieHindle 所说的那样。这似乎是混合了调试和非调试库的结果。 - jdigital
我已经重新构建了所有内容,包括发布和调试配置。我不确定您所说的调试/非调试库是什么意思。 - Christian A Strasser
1个回答

0
原来在尝试使程序兼容64位时,CFileStatus结构中的m_size元素从AFX.H文件中的LONG更改为ULONGLONG。问题在几个版本中一直潜伏着,但最近终于爆发了。不确定原因。无论如何,我将声明更改回LONG,现在似乎正常工作了。

1
哇...等一下...你把哪个声明从ULONGLONG改回了LONG告诉我你没有编辑afx.h文件! - Nik Bougalis
CFileStatus::m_size自VS 2003以来一直是ULONGLONG类型。听起来你的程序可能链接到使用VC6构建的库,其中该字段的类型为LONG(我不确定在VS 2002中该字段的类型是什么 - 我无法让该程序安装在我的Win7电脑上)。我认为你需要对整个程序/产品使用的库进行一些分析。在不理解为什么它们在你的构建中似乎无法工作的情况下,你肯定不应该修补库头文件。 - Michael Burr
我们仍在使用VS98(VC++ 6) - Christian A Strasser

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接