Closing doc in DocumentCreated event crashes

B

b.alex

Hi,

I've created a template with a DocumentCreated event handler. In that
handler, I look for certain conditions and may end up closing the document.
It works fine, but if I run Visio under a C++ debugger, I get "Unhandled
exception at 0x7c901230 in VISIO.EXE: User breakpoint" at some point after
closing the document. As an experiment, I can boil the code down to:

Private Sub Document_DocumentCreated(ByVal doc As IVDocument)
doc.Close
End Sub

I save that in a template, try creating a new drawing from the template a
couple of times, and the debugger gets the error. If I ignore the error and
keep running, things are fine. But the error worries and annoys me
nonetheless.

Am I breaking something by closing a document in its create event? Is there
an alternative way to do this?

Thanks,
Bob
 
B

b.alex

An important addendum: when I get the unhandled exception, the debugger's
output window also shows:

HEAP[VISIO.EXE]: HEAP: Free Heap block a06b08 modified at a06bb8 after it
was freed

So now I'm a little more alarmed about this. But I'm still at a loss for how
I caused this in Visual Basic.

This is Visio 2007, SP1.

- Bob
 
P

Paul Herber

Hi,

I've created a template with a DocumentCreated event handler. In that
handler, I look for certain conditions and may end up closing the document.
It works fine, but if I run Visio under a C++ debugger, I get "Unhandled
exception at 0x7c901230 in VISIO.EXE: User breakpoint" at some point after
closing the document. As an experiment, I can boil the code down to:

Private Sub Document_DocumentCreated(ByVal doc As IVDocument)
doc.Close
End Sub

I save that in a template, try creating a new drawing from the template a
couple of times, and the debugger gets the error. If I ignore the error and
keep running, things are fine. But the error worries and annoys me
nonetheless.

Am I breaking something by closing a document in its create event? Is there
an alternative way to do this?

There will almost certainly be code being executed after your event
handler that is expecting a valid document handle.
What to do about it? Instead of the doc.close how about putting a
custom event on the event queue that you can then interpret as a
document delete?
 
B

b.alex

Thanks, Paul. I suspected I'd need to do something asynchronous. I ended up
capturing the VisioIsIdle event and closing the document there.

- Bob
 
D

David Parker

Probably best to wait for NoEventsPending....

b.alex said:
Thanks, Paul. I suspected I'd need to do something asynchronous. I ended
up
capturing the VisioIsIdle event and closing the document there.

- Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top