NO

Author Topic: _except_handler  (Read 3133 times)

Alessio

  • Guest
_except_handler
« on: March 19, 2008, 11:00:52 am »
Hi,

How to use _except_handler ? I get this error:

Quote
error #2120: Redeclaration of '_except_handler' previously declared at C:\Alessio\Sviluppo\PellesC\Include\excpt.h(22): found 'EXCEPTION_DISPOSITION __cdecl function(LPEXCEPTION_RECORD, void *, LPCONTEXT, void *)', expected 'EXCEPTION_DISPOSITION __cdecl function((incomplete) struct _EXCEPTION_RECORD *, void *, (incomplete) struct _CONTEXT *, void *)'.

While compiling this:

Code: [Select]
EXCEPTION_DISPOSITION __cdecl _except_handler(struct _EXCEPTION_RECORD *lpExceptionRecord, void *lpEstablisherFrame, struct _CONTEXT *lpContextRecord, void *lpDispatcherContext)
{
char szBuf[256];
sprintf(szBuf, "Exception Code: %08X Exception Flags %X", lpExceptionRecord->ExceptionCode, lpExceptionRecord->ExceptionFlags);

if ( lpExceptionRecord->ExceptionFlags & 1 )
{
strcat(szBuf, " EH_NONCONTINUABLE");
}

    if ( lpExceptionRecord->ExceptionFlags & 2 )
{
strcat(szBuf, " EH_NONCONTINUABLE");
}

    if ( lpExceptionRecord->ExceptionFlags & 4 )
{
strcat(szBuf, " EH_UNWINDING");
}

    if ( lpExceptionRecord->ExceptionFlags & 8 )
{
strcat(szBuf, " EH_STACK_INVALID");
}

    if ( lpExceptionRecord->ExceptionFlags & 0x10 )
{
strcat(szBuf, " EH_NESTED_CALL");
}

printf(szBuf);
   
    return ExceptionContinueSearch;

UNREFERENCED_PARAMETER(lpDispatcherContext);
UNREFERENCED_PARAMETER(lpContextRecord);
UNREFERENCED_PARAMETER(lpEstablisherFrame);
}

Alessio

  • Guest
Re: _except_handler
« Reply #1 on: March 20, 2008, 04:59:22 pm »
I've fix that by adding following lines into "excpt.h" just before "_except_handler" definition:

Code: [Select]
struct _EXCEPTION_RECORD;
struct _CONTEXT;

but I've an inline asm error:

Code: [Select]
    DWORD handler = (DWORD)_except_handler;

    __asm
    {                           // Build EXCEPTION_REGISTRATION record:
        push    handler         // Address of handler function
        push    FS:[0]          // Address of previous handler
        mov     FS:[0],ESP      // Install new EXECEPTION_REGISTRATION
    }

    ...

for "push FS:[0]" I get "Invalid combination of opcode and operands."

Alessio

  • Guest
Re: _except_handler
« Reply #2 on: March 20, 2008, 11:21:09 pm »
Fixed! :)

Code: [Select]
    __asm
    {                         
        push    handler
        push    FS
        mov     FS:[0],ESP
    }