Re: MiniDumpWriteDump

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I changed the structure to use pointers instead of using the types inline
(see previous posting).
Now, when an exception occurs, and is caught my me (see sample code in same
posting), I actually get valid pointers to memory locations where useful
data about the nature of the exception can be found, unlike before.
I still get the "Invalid memory location" error when calling
MemoryDumpWriteDump however, so the wrong structure declaration must not
have been the only problem.

(Please forget my last posting's question about whether the API can access
the structure when I hand it over ByRef. I was being stupid.)

Robert

"Sam Hobbs" <samuel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23%23djmsTkFHA.1372@xxxxxxxxxxxxxxxxxxxxxxx
> Please explain.
>
> If you are not sure what to explain, then you can understand the
frustration
> of trying to understand something that is not clear.
>
>
> "Robert" <noone@xxxxxxxxxxx> wrote in message
> news:u7fcPhPkFHA.2852@xxxxxxxxxxxxxxxxxxxxxxx
> > OK, seems like the structure I had was actually filled with memory
> > garbage.
> >
> > Here's my attempt to improve things:
> >
> > ' New declare
> > Private Type EXCEPTION_POINTERS
> > pExceptionRecord As Long
> > pContextRecord As Long
> > End Type
> >
> > Now my question: If I get the EXCEPTION_POINTERS structure as a ByRef
> > parameter to a function, can I hand over a pointer to that structure to
an
> > API call directly, or won't the API call be able to access it from
there?
> > Do
> > I have to copy the whole contents of the structure (following all
> > pointers...) to the heap so the API call can access it? Because I still
> > get
> > the "Invalid access to memory location" error.
> >
> > Robert
> >
> > "Robert" <noone@xxxxxxxxxxx> wrote in message
> > news:OY7ekXPkFHA.2904@xxxxxxxxxxxxxxxxxxxxxxx
> >> Good point, the two of you, although I took those declares from
existing
> > VB
> >> samples (see example from this AllAPI page:
> >> http://www.mentalis.org/apilist/SetUnhandledExceptionFilter.shtml)
> >>
> >> I'll take a closer look at those structures, however.
> >>
> >> And here's the code that will call my function:
> >>
> >> First part goes into a Form, with two buttons named cmdSetFilter and
> >> cmdException
> >> When starting the app, first press cmdSetFilter, then cmdException (and
> > make
> >> sure you've saved the project before!)
> >> '*******************************************************************
> >>
> >> Private Declare Sub CopyMemoryRead Lib "kernel32" Alias _
> >> "RtlMoveMemory" (Destination As Any, ByVal Source As Long, _
> >> ByVal Length As Long)
> >>
> >> Private Sub cmdException_Click()
> >> Dim lngDest As Long
> >>
> >> ' Cause an exception
> >> Call CopyMemoryRead(lngDest, 0&, 4)
> >> End Sub
> >>
> >> Private Sub cmdSetFilter_Click()
> >> Call InitExceptionHandling
> >> End Sub
> >>
> >> '*******************************************************************
> >> ' Second part goes into a module (the same module as for the previous
> >> example)
> >>
> >> Private Const EXCEPTION_EXECUTE_HANDLER As Long = 1
> >>
> >> Private Declare Function SetUnhandledExceptionFilter Lib "kernel32" ( _
> >> ByVal lpTopLevelExceptionFilter As Long) As Long
> >>
> >> Private Declare Function UnhandledExceptionFilter Lib "kernel32" ( _
> >> ExceptionInfo As EXCEPTION_POINTERS) As Long
> >>
> >> Public Sub InitExceptionHandling()
> >> Debug.Print SetUnhandledExceptionFilter(AddressOf TopLevelFilter)
> >> End Sub
> >>
> >> Public Function TopLevelFilter(ByRef pExc As EXCEPTION_POINTERS) As
Long
> >> Dim rc As Long
> >>
> >> ' My function call
> >> rc = WriteMiniDump(pExc)
> >>
> >> Call MsgBox("I caught an exception!" + vbCr + "Minidump result: " +
> >> CStr(Hex(rc)))
> >>
> >> TopLevelFilter = EXCEPTION_EXECUTE_HANDLER
> >> End Function
> >>
> >>
> >> Robert
> >>
> >> "Sam Hobbs" <samuel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
> >> message
> >> news:%232c2$oujFHA.3544@xxxxxxxxxxxxxxxxxxxxxxx
> >> > "Robert" <noone@xxxxxxxxxxx> wrote in message
> >> > news:e5xQMUrjFHA.1416@xxxxxxxxxxxxxxxxxxxxxxx
> >> > >I found a lot of MiniDumpWriteDump, too, but all for VC, not VB.
> >> >
> >> > Yes, it does seem that there are not any VB examples available.
> >> >
> >> > I have copied your code into a module, but I am not familiar with
this
> >> API.
> >> > It might not be easy for me to find the problem. However in order for
> >> > me
> >> to
> >> > try, I should learn enough to know how to use the code you have. I
> >> > might
> >> not
> >> > have the time but I hope someone does. However can you provide a
sample
> > of
> >> > how you are calling the functions?
> >> >
> >> > One thing I notice is that there are a lot of structs (UDTs). Are you
> >> > familiar with packing? Are you sure that is not a problem?
> >> >
> >> > > Private Type EXCEPTION_POINTERS
> >> > > pExceptionRecord As EXCEPTION_RECORD
> >> > > ContextRecord As CONTEXT
> >> > > End Type
> >> >
> >> > I think this is a problem. The C definition of EXCEPTION_POINTERS is:
> >> >
> >> > typedef struct _EXCEPTION_POINTERS {
> >> > PEXCEPTION_RECORD ExceptionRecord;
> >> > PCONTEXT ContextRecord;
> >> > } EXCEPTION_POINTERS;
> >> >
> >> > Note that ExceptionRecord and ContextRecord are pointers, whereas
your
> > UDT
> >> > has the UDTs/structs in your UDT for EXCEPTION_POINTERS. Check your
> > other
> >> > UDTs to ensure they are also correct.
> >> >
> >> > > Currently, I get the error
> >> > > -2147023898 (0x800703E6)
> >> > > Invalid access to memory location
> >> >
> >> > It helps to know where in the code the exception occurs. However that
> >> > exception might be caused by the problem I described above.
> >> >
> >> >
> >>
> >>
> >
> >
>
>


.



Relevant Pages

  • Re: MiniDumpWriteDump
    ... > API call directly, or won't the API call be able to access it from there? ... >> End Sub ... >>> One thing I notice is that there are a lot of structs (UDTs). ... >>> It helps to know where in the code the exception occurs. ...
    (microsoft.public.vb.winapi)
  • Re: Exception as the primary error handling mechanism?
    ... and reduced defect rate against machine efficiency too. ... example of an API that is simply poor: ... exception than it is to make unnecessary tests. ... more complex code, lowered readability and usability, and more defects, ...
    (comp.lang.python)
  • Re: Exception as the primary error handling mechanism?
    ... Does this imply that putting code in functions is a poor API? ... exception than it is to make unnecessary tests. ... The difficulty for the API designer is to make ... caller and can extract a performance penalty that may be unacceptable ...
    (comp.lang.python)
  • Re: Differences in data description in programming languages
    ... That certainly is true of statics _and_ automatics. ... >>Those can happen in Cobol too, and have nothing to do with pointers. ... OO systems an exception will be passed up the process until it is ...
    (comp.lang.cobol)
  • Re: Exception as the primary error handling mechanism?
    ... In the article API Design Matters by Michi Henning ... In many language implementations, exception handling is expensive; ... the caller will treat the condition as an unexpected ...
    (comp.lang.python)