简单的弦比较如何引起olexeception
How can a simple string comparison cause an OleException?
我有此C 代码:
static CString timeout(_T("TIMEOUT"));
if(strError.Left(7).CompareNoCase(timeout) == 0) return TRUE;
在我的直接窗口中,我看到了strError
的以下值:
? strError
L""
ATL::CSimpleStringT<wchar_t,1>: L""
我正在遵循异常(我正在调试崩溃转储):
Unhandled exception at 0x74B4A9F2 in CRASH.DMP: Microsoft C++ exception:
COleException at memory location 0x01BFFD14. occurred
我的呼叫堆栈如下:
KERNELBASE.dll!_RaiseException@16() Unknown
msvcr110.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 152 C++
mfc110u.dll!AfxThrowOleException(long) Unknown
mfc110u.dll!ATL::AtlThrowImpl(long) Unknown
mfc110u.dll!ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > >::CompareNoCase(wchar_t const *) Unknown
> <Application>.exe!<Own_Class>::<Own_Function>(const ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t,ATL::ChTraitsCRT<wchar_t> > > & strError) Line 106 C++
当我检查一个空字符串的.Left(7)
时崩溃时,我立即认为这是问题的过程。但是,我已经意识到,这件代码通常运行良好(我只是对此进行了仔细检查),并且在仔细查看时,我会发现如果不是违规或NullPoInterException,则例外,而是与OLE相关的例外。与此同时,我了解到该问题不在strError.Left(7)
部分中:这似乎是CompareNoCase()
方法,但是怎么了,但是如何?
任何人都可以启发我的代码中有什么错?
就strError
而言,它的创建如下:
CString strError;
...
strError = <function>();
其中 <function>()
是:
CString <function>(){
...
return _T("fix string"); // or:
return <Complicated_function_handling>();
在这种特殊情况下,我不知道是如何创建strError
的(我知道它是空的,正如在即时窗口中清楚地看到的,但是我只有崩溃转储,所以我可以读取当前值,但是我不喜欢知道他们的历史)。
一件事,这可能会有所帮助:我已经要求strError
的内存地址,并且我已经查看了内存中的数据(使用Visual Studio Memory调试窗口),并且我得到以下数据:
5c 18 9c 71 38 d9 ca 00 03 00 00 00 cc 3d c2 00 70 fe bf 01 94 13 b3 00 39 00 00 00 80 fe bf 01 be 58 aa 00 b0 3d c2 00 10 0c cd 00 44 03 00 00 01 00 00 00 d3 5f ac 00 8a 40 1d 72 8e f2 d6 73
预先感谢
通过MFC的来源工作,因为timeOut
是一个空字符串,因此正在抛出例外。如果尚未构建这种情况,或者已经被破坏了。COleException
中存储的错误代码是E_FAIL
。
呼叫序列是这样的:
-
CompareNoCase
调用AtlIsValidString
(如果timeOut
转换为const char *
,则在您的情况下返回false,为null)。 - 由于
AtlIsValidString
返回false,因此与ATLENSURE
宏连接的代码AtlThrow(E_FAIL)
(AtlThrow
是一个宏,定义为ATL::AtlThrowImpl
。 -
AtlThrowImpl
调用AfxThrowOleException
,因为错误代码不是E_OUTOFMEMORY
。
相关文章:
- 函数何时会在c++中包含stack_Unwind_Resume调用
- Python中的for循环与C++有何不同
- QScrollArea:由垂直滚动条引起的水平滚动条
- 由cin中的字符串中未捕获空白引起的分割错误
- 在C++中释放内存期间,迭代器与指针有何不同
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- C1001内部编译器错误是由于矢量初始化(如数组)引起的
- C2675 一元运算符由错误的作用域引起
- 由于矢量引起的错误<string>?
- 类中的 C++ int 被设置为值,似乎不知从何而来
- -fvisibility-inline-hidden 与 gcc 中的 -fvisibility=hidden 有何不同
- 将 opencv 从 2.4.13 转换为 3.3.1 时由 cv::resize() 引起的运行错误
- 收益率和回报有何不同?
- 覆盖私有功能,它与受保护功能有何不同?
- cv::resize() 失败并出现访问冲突错误(由 NULL> 处的 <struct 引起)
- 擦除删除成语的性能增益从何而来
- 用wchar_t处理 unicode 字符好吗?它不会引起任何问题吗?
- 无论代码长度如何,以下代码的内存要求有何不同?
- "virtual"对C++析构函数有何影响?
- 如果我对"while"块发表评论,为什么程序会死机?其中的"yield"线有何影响?