开发环境 winxp sp2 vc++7.0
编译时总是出现 error C3861: “AddVectoredExceptionHandler”: 即使使用参数相关的查找,也未找到标识符
我选中AddVectoredExceptionHandler 右击它 选转到定义 能找到声明的啊 是在winbase.h中的 我头文件都包括了阿
工程共三个文件
stdafx.h 内容为
#pragma once
#include <iostream>
#include <tchar.h>
#include "windows.h"
#include "winbase.h "
stdafx.cpp 内容为
#include "stdafx.h"
VectoredException.cpp 内容为
#include "stdafx.h"
LONG Sequence=1;
LONG Actual[3];
LONG WINAPI
VectoredHandler1(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
Actual[0] = Sequence++;
return EXCEPTION_CONTINUE_SEARCH;
}
LONG WINAPI
VectoredHandler2(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
Actual[1] = Sequence++;
return EXCEPTION_CONTINUE_SEARCH;
}
LONG WINAPI
VectoredHandler3(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
Actual[2] = Sequence++;
return EXCEPTION_CONTINUE_SEARCH;
}
LONG WINAPI
VectoredHandlerSkip1(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
PCONTEXT Context;
Sequence++;
Context = ExceptionInfo->ContextRecord;
Actual[0] = 0xcc;
Context->Eip++;
return EXCEPTION_CONTINUE_EXECUTION;
}
LONG WINAPI
VectoredHandlerSkip2(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
PCONTEXT Context;
Sequence++;
Context = ExceptionInfo->ContextRecord;
Actual[1] = 0xcc;
Context->Eip++;
return EXCEPTION_CONTINUE_EXECUTION;
}
LONG WINAPI
VectoredHandlerSkip3(
struct _EXCEPTION_POINTERS *ExceptionInfo
)
{
PCONTEXT Context;
Sequence++;
Context = ExceptionInfo->ContextRecord;
Actual[2] = 0xcc;
Context->Eip++;
return EXCEPTION_CONTINUE_EXECUTION;
}
BOOL
CheckTest(
char *Variation,
PLONG e,
PLONG a
)
{
int i;
BOOL Pass = TRUE;
for(i=0;i<3;i++)
{
if (e[i] != a[i])
{
if (Variation)
{
printf("%s Failed at %d Expected %d vs Actual %d\n",
Variation, i, e[i], a[i]);
}
Pass = FALSE;
}
// Clear actual for next pass.
a[i] = 0;
}
// Get ready for next pass.
Sequence = 1;
if (Variation)
{
printf("Variation %s %s\n", Variation,
Pass ? "Passed" : "Failed");
}
return Pass;
}
void
CheckAllClear()
{
LONG e[3];
BOOL b;
e[0]=0;e[1]=0;e[2]=0;
__try
{
RaiseException(1,0,0,NULL);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
b = CheckTest(NULL,e,Actual);
}
if (!b)
{
printf("Fatal error, handlers still registered.\n");
}
}
void
IllegalInst()
{
_asm {cli};
}
void
Test1()
{
PVOID h1,h2,h3;
LONG e[3];
e[0]=1;e[1]=2;e[2]=3;
h2 = AddVectoredExceptionHandler(1,VectoredHandler2);
h3 = AddVectoredExceptionHandler(0,VectoredHandler3);
h1 = AddVectoredExceptionHandler(1,VectoredHandler1);
__try
{
RaiseException(1,0,0,NULL);
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
CheckTest("Test1a",e,Actual);
}
RemoveVectoredExceptionHandler(h1);
RemoveVectoredExceptionHandler(h3);
RemoveVectoredExceptionHandler(h2);
CheckAllClear();
}
void
Test2()
{
PVOID h1,h2,h3;
LONG e[3];
e[0]=0xcc;e[1]=0;e[2]=0;
h1 = AddVectoredExceptionHandler(1,VectoredHandlerSkip1);
IllegalInst();
CheckTest("Test2a",e,Actual);
RemoveVectoredExceptionHandler(h1);
CheckAllClear();
e[0]=1;e[1]=2;e[2]=0xcc;
h2 = AddVectoredExceptionHandler(1,VectoredHandler2);
h3 = AddVectoredExceptionHandler(0,VectoredHandlerSkip3);
h1 = AddVectoredExceptionHandler(1,VectoredHandler1);
IllegalInst();
CheckTest("Test2b",e,Actual);
RemoveVectoredExceptionHandler(h1);
RemoveVectoredExceptionHandler(h2);
RemoveVectoredExceptionHandler(h3);
CheckAllClear();
e[0]=1;e[1]=0xcc;e[2]=0;
h1 = AddVectoredExceptionHandler(0,VectoredHandler1);
h2 = AddVectoredExceptionHandler(0,VectoredHandlerSkip2);
h3 = AddVectoredExceptionHandler(0,VectoredHandler3);
IllegalInst();
CheckTest("Test2c",e,Actual);
RemoveVectoredExceptionHandler(h1);
RemoveVectoredExceptionHandler(h2);
RemoveVectoredExceptionHandler(h3);
CheckAllClear();
e[0]=2;e[1]=0xcc;e[2]=1;
h1 = AddVectoredExceptionHandler(0,VectoredHandler1);
h3 = AddVectoredExceptionHandler(1,VectoredHandler3);
h2 = AddVectoredExceptionHandler(0,VectoredHandlerSkip2);
__try
{
IllegalInst();
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
// Should not make it to here.
e[0]=0;e[1]=0;e[2]=0;
CheckTest("Test2d-1",e,Actual);
}
CheckTest("Test2d-2",e,Actual);
RemoveVectoredExceptionHandler(h1);
RemoveVectoredExceptionHandler(h2);
RemoveVectoredExceptionHandler(h3);
CheckAllClear();
}
int _tmain(int argc, _TCHAR* argv[])
{
Test1();
Test2();
return 0;
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!