【发布时间】:2013-08-23 04:20:54
【问题描述】:
对于 C++ 代码中的异常处理程序,我需要以下内容。说,我有以下代码块:
void myFunction(LPCTSTR pStr, int ncbNumCharsInStr)
{
__try
{
//Do work with 'pStr'
}
__except(1)
{
//Catch all
//But here I need to log `pStr` into event log
//For that I don't want to raise another exception
//if memory block of size `ncbNumCharsInStr` * sizeof(TCHAR)
//pointed by 'pStr' is unreadable.
if(memory_readable(pStr, ncbNumCharsInStr * sizeof(TCHAR)))
{
Log(L"Failed processing: %s", pStr);
}
else
{
Log(L"String at 0x%X, %d chars long is unreadable!", pStr, ncbNumCharsInStr);
}
}
}
有没有办法实现memory_readable?
【问题讨论】:
-
IsBadReadPtr()不适合你吗? -
根据该页面的文档,结构化异常处理是可行的方法,除非我解释不正确。我从来没有这样做过,所以我可能是。
-
在您尝试执行此操作之前,请先阅读这篇文章:blogs.msdn.com/b/oldnewthing/archive/2006/09/27/773741.aspx
-
@Naveen,MSDN 文章需要在适当的地方链接到 Raymond Chen 的帖子:p
-
@c00000fd:不正确的程序不值得运行。
标签: c++ windows winapi memory-management