Visio causes strange behaviour

C

Chris

I have a VB6 standalone EXE that uses the Visio COM library to add master
shapes to a Visio file. There is no user interaction and the shapes are
added quickly in succession although I yield (Doevents & Sleep) in between
adding shapes because it seems to reduce crashing.

However, I still get the following strange behaviour and crashes in the
EXE:-
1) The EXE will sometimes crash after leaving a method that has added new
shapes to the Visio page. (I guess it is the memory cleanup).
2) The parameters that a method receives are sometimes different to the ones
passed. For example, If I pass a string value MyString (ByVal) to a method
which then calls itself again and passes MyString unchanged then on entry to
the 2nd call the value of MyString has changed. There is nothing (and I do
mean nothing) that changes MyString.

Are there known problems doing this type of thing in Visio? I have
re-installed Visio and Visual Studio as well as the latest SPs.
 
L

LarryF

The symptoms you describe are a program stack corruption.

If a program crashes during a return from a method, it means that
something that happened in that method overwrote the method's return
address on the stack. VB6 stores the return address, the call
parameters, and the local variables on the program stack. Both of your
symptoms, the corrupted parameters and the corrupted return address,
are symptoms of the same problem: something, probably a COM function,
is corrupting your stack. Calling DoEvents or Sleep won't fix the
problem, but it may make the crash happen more or less frequently.

It is very hard for a VB6 program to corrupt its own stack, but when a
VB6 program calls a C routine, that routine can easily corrupt the
stack, most often because of incorrect parameters you pass, or possibly
because of a bug in the called routine. You probably haven't found a
new bug, so I suspect that your parameters to the COM function aren't
quite right.

For example, if you pass a 2-byte Integer into a COM routine that
expects a 4-byte Long, that routine will write 4 bytes into your 2-byte
integer, corrupting whatever is next on the stack. Check all your
calling parameters into the COM calls to make sure you always pass in
exactly the right type. Also don't pass in fixed length strings; use
the regular String type.

I use a VB6 .exe to create Visio drawings through COM, and I even use
recursion like you do. Something in your code is causing Visio to trash
your stack.

Good luck finding it,

Larry
 

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