我已经创建了控制台应用程序,我从中调用了Win32项目,它会引发访问冲突异常。我在!clrstack
附加了我的自定义过滤器。当我使用public void ExceptionMethod()
{
ExceptionCreator.CreateAccessViolationException();
}
命令时,它显示非托管调用堆栈,但MSDN表示Clrstack将仅提供托管代码的堆栈跟踪。
请帮忙。
Program.cs的
#pragma once
#include "stdafx.h"
#include "DbgHelp.h"
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Text;
public ref class ErrorReportWritter
{
public:
static void InstallHandler();
};
Win32项目:
ErrorReportWritter.h
LONG WINAPI MyExceptionFilter(__in struct _EXCEPTION_POINTERS *ExceptionInfo)
{
//For test purpose, Dump location will be the solution location itself
HANDLE hFile = CreateFileA("Test.dmp", GENERIC_READ | GENERIC_WRITE,
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
{
// Create the maxidump
MINIDUMP_TYPE mdt = (MINIDUMP_TYPE)(MiniDumpWithFullMemory |
MiniDumpWithFullMemoryInfo |
MiniDumpWithHandleData |
MiniDumpWithThreadInfo |
MiniDumpWithUnloadedModules);
//MINIDUMP_TYPE mdt = MiniDumpNormal;
MINIDUMP_EXCEPTION_INFORMATION mei;
mei.ThreadId = GetCurrentThreadId();
mei.ClientPointers = FALSE;
mei.ExceptionPointers = ExceptionInfo;
BOOL rv = MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, mdt, &mei, 0, 0);
//TODO: put a check for failure return value and throw exception in that case
// Close the file
CloseHandle(hFile);
}
//TODO: Still need to decide if the search next functionality is needed for final solution
if (oldFilter == NULL)
{
return EXCEPTION_CONTINUE_SEARCH;
}
LONG ret = oldFilter(ExceptionInfo);
return ret;
}
void ErrorReportWritter::InstallHandler()
{
//Returns the address of the previous exception filter established with the function.
//A NULL return value means that there is no current top-level exception handler.
oldFilter = SetUnhandledExceptionFilter(MyExceptionFilter);
}
ErrorReportWritter.cpp
memory cannot be written
https://msdn.microsoft.com/en-us/library/bb190764(v=vs.110).aspx
答案 0 :(得分:0)
您拥有的代码是托管 C ++。 (或C ++ / CLI或Visual Studio版本支持的任何内容)。
要创建非托管 Win32项目,例如在Visual Studio 2015中,请转到File
- > New Project
然后选择Templates
- > Visual C++
- > Win32 Project
。