tags:

views:

347

answers:

4

Hi all!!!

I have a little problem with visual basic 6 project. Everything works fine in the IDE but when the executable crashes every time I run the application. The application uses callbacks to communicate with a C++ dll. Even code as simple as showing a message box fails when the callback starts.

I changed the compilation mode to P-Code and still the problem persist.

Any help would be appreciate.

Thank you all

A: 

Is the code being run from the same location as the IDE? Likely it is a reference problem, and you need to re-register the DLL.

A deployment package should make sure you have everything installed.

IPX Ares
yea is the same location, in fact other calls to the same dll work just fine
JP Berrocal
are you late or early binding? Also the below comments are right as well... posting the segment of code that is causing the crash / calling the object would be nice.
IPX Ares
A: 

Who's calling back to whom? Show us a little code.

The IDE can mask real problems, so just being able to run there is no guarantee that what you're doing is supported.

One common problem with callbacks is that VB6's runtime is not thread-safe, so if another thread is calling back into your VB code, you can't do anything that will invoke the runtime -- like access strings or objects.

There are ways around some of these issues, but I think we need to know more first.

Jim Mack
A: 

A few questions:

  1. Is the executable on the same PC as it was developed, or a different one?
  2. Does the file use a manifest file? If so, does mainfest call XP themes?
  3. Also, if using manifest, does manifest use SXS for OCX files?
OneNerd
+1  A: 

This sounds like the callbacks may be occurring on a different thread than your application is executing on. [EDIT: As I see Jim has already suggested.] If that's the case, yeah, kaboom just as soon as you "touch" anything OLE related or call into the runtime. Same story as with multimedia timer callbacks, fwiw, and I'd suspect you'll have to take the same precautions as one would with those if this is the case.

The short story with different thread callbacks is that you'll need to post a message to yourself, using PostMessage declared in a typelib so that the Err object isn't set by VB, then let the callback return. You do your own processing on receipt of the posted message. Here's the typelib I used for this with the CCRP Timers library:

http://vb.mvps.org/tools/files/postmessage.zip

Hope that helps...

Karl E. Peterson
Thank you very much Karl, and sorry for my ignorance but this is my first visual basic 6 project. How do I use the tlb file, i tried adding a reference in VB IDE but is not working, and can i pass a struct or class type to the postMethod because the callback returns to me 4 values.
JP Berrocal