Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Access Violation Exception

42 views
Skip to first unread message

Ivan Debono

unread,
Sep 15, 2005, 8:26:24 AM9/15/05
to
Hi all,

I have a problem that's driving me crazy!!!

I have a vb6 app with various custom controls. One of them is the CommandBar
control from vbAccelerator. The app hooks into the clipboard notification
queue so that it knows what's being copied and pasted. All controls that I
use (apart from the CommandBar) have 2 distinct error handling functions:

1. SetUnhandledExceptionFilter
2. Log writing

The 2nd method simply writes to a text file in places where I add the
function and always in the error handling routine most functions. It is the
first method that capture the Access Violation Exception.

The problem has 2 symptons:

1. App just crashes with no error message
2. App enters into a loop where it displays the exception error and it looks
like the source is in the CommandBar control (the messagebox title says so!)

I've used the CommandBar control a gazillion times and I never had problems
with it. It is only this combination that is causing the error. I have to
add the control itself doesn't handle errors at all (or maybe in a couple of
places only), and there's quite a few lines of code. Problem is that I can't
run it the IDE as it won't work, so compiling everything and running the
app.

Before I start adding Logwrite functions in each and every function of the
control, is there a way to geenrate more information on the exception, such
as the function (and/or line) that is causing it. Can I create a pdb file
that can be used with some sort of tool to help me trace the exception
source? Are there such tools available?

Help!!

Ivan


[SolarAngel]

unread,
Sep 15, 2005, 11:07:22 AM9/15/05
to

Access Violation Exception known as 0x05 error (Read/Write access)

I had similar problem many times, and it was usualy bad pointer.
there is some error in your code with pointer some pointer is pointing to memory not owned by your process!
you have next API's
Public Declare Function IsBadCodePtr Lib "kernel32" (ByRef lpFarProc As Any) As Long
Public Declare Function IsBadReadPtr Lib "kernel32" (ByRef lp As Any, ByVal ucb As Long) As Long
Public Declare Function IsBadStringPtr Lib "kernel32" (ByRef lpStr As Any, ByVal ucb As Long) As Long
Public Declare Function IsBadWritePtr Lib "kernel32" (ByRef lp As Any, ByVal ucb As Long) As Long

you can use them to verify exact point where your problem has occured, but it might not be in place you said, it could be at some
other point for example, you have made clipboard notification, for clipboard to send you an event he must call some memory address
in you application but if that address does not belong to your process it will likely crash (I asume that that is a problem) or
something similar check if you have any hooks or other notifications.

I am interested how did you implement SetUnhandledExceptionFilter, could you paste us some code?

[SolarAngel]

"Ivan Debono" <ivan...@hotmail.com> wrote in message news:eErAp$euFHA...@TK2MSFTNGP09.phx.gbl...

| Processed by 'SolarAngel-yVBProxy Ver:1.03.0100' contact yvbp...@www.yu for more information!


Someone

unread,
Sep 16, 2005, 2:08:29 AM9/16/05
to
- In VB6, in the project's properties, go to the Compile tab and select
"Create symbolic debug info". This will create a PDB file when you compile
your project.
- Remove the calls to SetUnhandledExceptionFilter.
- Save and Compile.
- Run the EXE from Windows Explorer.
- Go to VC++ 6.0|File|Close Workspace.
- Go to Build|Start Debug|Attach to process, and select your running EXE.
- Go to View|Debug Windows, and make sure that "Call Stack" window is
visible.
- Let it crash.
- The call stack shows you where the problem is. One of the lines will point
to your source code, when you double click on that, it will show you the
source code and points to the exact line that caused the error.
- If the program closed normally, or you want to try again, go to
Build|Execute <Your EXE file name>.
- There are some settings that you could change, if necessary, in
Project|Settings|Debug.

If the crash is caused by a custom control, you will have to compile that
with debug info as well, otherwise, VC++ will not show you the source line
where the error occurred in the custom control. If this happens, the line
highlighted in your code is a property or method call to that custom
control.


"Ivan Debono" <ivan...@hotmail.com> wrote in message
news:eErAp$euFHA...@TK2MSFTNGP09.phx.gbl...

Ivan Debono

unread,
Sep 16, 2005, 2:38:05 AM9/16/05
to
Hi,

Here's the code. This is the basic function that I used to further improve
my own but it gets you started.

'In a form (Form)

Private Sub Form_Load()

'Make sure all unhandled errors are caught by our procedure

SetUnhandledExceptionFilter AddressOf MyExceptionHandler

'Raise an unhandled exception

RaiseException 0, 0, 0, 0

End Sub

Private Sub Form_Unload(Cancel As Integer)

'Remove the hook

SetUnhandledExceptionFilter ByVal 0&

End Sub

'In a Module

Public Const EXCEPTION_CONTINUE_EXECUTION = -1

Public Const EXCEPTION_CONTINUE_SEARCH = 0

Public Const EXCEPTION_MAXIMUM_PARAMETERS = 15

Public Type CONTEXT

FltF0 As Double

FltF1 As Double

FltF2 As Double

FltF3 As Double

FltF4 As Double

FltF5 As Double

FltF6 As Double

FltF7 As Double

FltF8 As Double

FltF9 As Double

FltF10 As Double

FltF11 As Double

FltF12 As Double

FltF13 As Double

FltF14 As Double

FltF15 As Double

FltF16 As Double

FltF17 As Double

FltF18 As Double

FltF19 As Double

FltF20 As Double

FltF21 As Double

FltF22 As Double

FltF23 As Double

FltF24 As Double

FltF25 As Double

FltF26 As Double

FltF27 As Double

FltF28 As Double

FltF29 As Double

FltF30 As Double

FltF31 As Double

IntV0 As Double

IntT0 As Double

IntT1 As Double

IntT2 As Double

IntT3 As Double

IntT4 As Double

IntT5 As Double

IntT6 As Double

IntT7 As Double

IntS0 As Double

IntS1 As Double

IntS2 As Double

IntS3 As Double

IntS4 As Double

IntS5 As Double

IntFp As Double

IntA0 As Double

IntA1 As Double

IntA2 As Double

IntA3 As Double

IntA4 As Double

IntA5 As Double

IntT8 As Double

IntT9 As Double

IntT10 As Double

IntT11 As Double

IntRa As Double

IntT12 As Double

IntAt As Double

IntGp As Double

IntSp As Double

IntZero As Double

Fpcr As Double

SoftFpcr As Double

Fir As Double

Psr As Long

ContextFlags As Long

Fill(4) As Long

End Type

Public Type EXCEPTION_RECORD

ExceptionCode As Long

ExceptionFlags As Long

pExceptionRecord As Long ' Pointer to an EXCEPTION_RECORD structure

ExceptionAddress As Long

NumberParameters As Long

ExceptionInformation(EXCEPTION_MAXIMUM_PARAMETERS - 1) As Long

End Type

Public Type EXCEPTION_POINTERS

pExceptionRecord As EXCEPTION_RECORD

ContextRecord As CONTEXT

End Type

Public Enum EFaultRepRetVal

frrvOk = 0

frrvOkManifest = 1

frrvOkQueued = 2

frrvErr = 3

frrvErrNoDW = 4

frrvErrTimeout = 5

frrvLaunchDebugger = 6

frrvOkHeadless = 7

End Enum

Public Declare Function ReportFault Lib "Faultrep" (pep As
EXCEPTION_POINTERS, ByVal dwMode As Long) As EFaultRepRetVal

Public Declare Sub RaiseException Lib "kernel32" (ByVal dwExceptionCode As
Long, ByVal dwExceptionFlags As Long, ByVal nNumberOfArguments As Long,
lpArguments As Long)

Public Declare Function SetUnhandledExceptionFilter Lib "kernel32" (ByVal
lpTopLevelExceptionFilter As Long) As Long

Public Function MyExceptionHandler(lpEP As EXCEPTION_POINTERS) As Long

'Show the WindowsXP Error Reporting dialog

ReportFault lpEP, 0

'Continue execution

MyExceptionHandler = EXCEPTION_CONTINUE_EXECUTION

End Function

"[SolarAngel]" <not-for-mail> schrieb im Newsbeitrag
news:%2303MPcg...@TK2MSFTNGP12.phx.gbl...

Ivan Debono

unread,
Sep 16, 2005, 2:53:20 AM9/16/05
to
I've been trying to do it with WinDbg but it somehow slowed down my App to a
near halt. I didn't know I could do it with VC++6. I have only VC++.Net 2003
installed at the moment. Would it work with that too?

Ivan

"Someone" <nob...@cox.net> schrieb im Newsbeitrag
news:njtWe.36391$ct5.22700@fed1read04...

Someone

unread,
Sep 16, 2005, 4:03:54 AM9/16/05
to
> I have only VC++.Net 2003
> installed at the moment. Would it work with that too?

Yes. Go to Tools|Debug Process, select your process and click Attach, and
then select Native. You could View the call stack by going to
Debug|Windows|Call Stack. Debug|Exception lets you control what happens when
an exception occurs. By default, it breaks in the debugger for Access
Violation and most unhandled Win32 Exceptions.

I forgot to mention in my last email that when you are viewing VB6 source
code, you could right click on a line and select "Go to Disassembly". This
works in both VC 6.0 and .Net 2003, just tested both.


"Ivan Debono" <ivan...@hotmail.com> wrote in message

news:%23kxvLqo...@TK2MSFTNGP10.phx.gbl...

Ivan Debono

unread,
Sep 16, 2005, 5:03:53 AM9/16/05
to
Cool that's great!! We have to test it over the weekend!!

Does the disassembly show the assembly code or the vb code?

Ivan

"Someone" <nob...@cox.net> schrieb im Newsbeitrag

news:z%uWe.38080$ct5.27777@fed1read04...

Someone

unread,
Sep 16, 2005, 10:34:14 AM9/16/05
to
> Does the disassembly show the assembly code or the vb code?

If you have the PDB file, it shows both in mixed mode, if you don't have it,
it shows the assembly only.


"Ivan Debono" <ivan...@hotmail.com> wrote in message

news:OXLEJzpu...@TK2MSFTNGP12.phx.gbl...

Ivan Debono

unread,
Sep 16, 2005, 11:46:05 PM9/16/05
to
Works like a charm!! Thanks.

Ivan

"Someone" <nob...@cox.net> schrieb im Newsbeitrag

news:wJAWe.42238$ct5.40294@fed1read04...

Ivan Debono

unread,
Sep 17, 2005, 1:57:05 AM9/17/05
to
I've solved the first bug. But I've got another bug and this is more strange
than the first.

When I close the app, I get a messagebox with an exclamation icon that says:
Runtime error '0'. The app ends normally though.

I've checked my source code, and there's no such messagebox that's being
displayed. The eventviewer shows nothing too.

Is there a way to locate the error source for this bug?

Thanks,
Ivan

"Someone" <nob...@cox.net> schrieb im Newsbeitrag

news:wJAWe.42238$ct5.40294@fed1read04...

Someone

unread,
Sep 17, 2005, 10:12:38 AM9/17/05
to
> Is there a way to locate the error source for this bug?

When the dialog appears, don't click it. Go to Debug|Break, and look at the
Call Stack. It may not point to a source code line though.

Some people have found anomalies in the Err object. One way to reduce them
is setting everything that you set a reference to; to Nothing in
Form_Unload. Use Erase <Dynamic array name>, to release memory used by
dynamic arrays...

"Ivan Debono" <ivan...@hotmail.com> wrote in message

news:OzQ1iy0u...@TK2MSFTNGP09.phx.gbl...

Ivan Debono

unread,
Sep 17, 2005, 10:25:31 AM9/17/05
to
Did that. Very funny behavior. It highlights a line that is in a function
and this function is usually called on Form_load or Usercontrol_Initialize.

Apart from that I'm very environment-friendly and I take care of my garbage
collection !!

Ivan


"Someone" <nob...@cox.net> schrieb im Newsbeitrag

news:dvVWe.42306$ct5.41922@fed1read04...

Someone

unread,
Sep 17, 2005, 10:50:49 AM9/17/05
to
Do you have MZ Tools? If you do then go to that function, and click on
"Procedure Callers", this will show you what routines that call that
function.

http://www.mztools.com/v3/mztools3.htm

"Ivan Debono" <ivan...@hotmail.com> wrote in message

news:eA7HqO5u...@TK2MSFTNGP14.phx.gbl...

Ivan Debono

unread,
Sep 17, 2005, 11:59:32 AM9/17/05
to
I finally figured it out. Jeez... the wrong error message in the wrong
place... sure was quite a nasty one this time :)

Ivan

"Someone" <nob...@cox.net> schrieb im Newsbeitrag

news:13WWe.42313$ct5.16273@fed1read04...

[SolarAngel]

unread,
Sep 19, 2005, 9:38:42 AM9/19/05
to

Your Example is nice but I have problem with VC++ 6.0, it doesn't show any processes (Build|Start Debug|Attach to process) why is
this!?
Also there is no list of processes for System Processes !?

OS: WIN2K SP2 (with some patches)
MSVB6.0 SP5 ED
MSVC++ 6.0 ED

What could be the problem with my Visual C++?

[SolarAngel]

"Someone" <nob...@cox.net> wrote in message news:njtWe.36391$ct5.22700@fed1read04...

Someone

unread,
Sep 19, 2005, 9:49:20 AM9/19/05
to
It must be a permission issue. I am not sure what is required. Try a Power
User on an Admin Account. You could see what group you are in by going to
Control Panel|Administrative Tools|Computer Management. Note that "Domain
Admin" is not the same as "Administrator".


"[SolarAngel]" <not-for-mail> wrote in message
news:eoXSl9Rv...@TK2MSFTNGP09.phx.gbl...

[SolarAngel]

unread,
Sep 20, 2005, 9:32:51 AM9/20/05
to

Well I am using Built in Administrator account (renamed to Admin) I am guessing that this should have enough permissions.
It must be somethig MSVC++ releated staff.

But I have success debuging VBProjects:
Open MSVC, close workspace, add EXE file (creating new workspace), and start EXE from the inside of MSVC, he will capture all
exceptions and I can debug as you have mentioned before.

[SolarAngel]

"Someone" <nob...@cox.net> wrote in message news:ilzXe.43226$ct5.31593@fed1read04...

0 new messages