Debugging some *strange* COM behavior

Status
Not open for further replies.
Greetings, fellow programmers,

I am trying to figure out some strangeness in using an external COM object from my own COM object, via simple inclusion (i.e. my object uses another object through standard CoCreateInstance and related API, there is no aggregation or anything funky happening). Without going into too much detail - trust me, it'd be impossible to compress it all into a single post - here is what seems to be happening:

1) I call CoCreateInstance() on an external object. The return HRESULT is S_OK.
2) My *own* object is starting to behave strangely. Variables that are supposed to have values in them are trashed. Unfortunately it is very hard to figure out what exactly IS in the object, and what's happening at any given point, because of the copious amounts of inheritance and various other C++ trickery going on. This isn't my code, and is most definately not my idea of a good design. Anyway, I shortly encounter a crash due to following a NULL pointer which *I know* held a valid value before I called the CoCreateInstance().

My conclusion from 1 & 2, is that the code for my object, screwed up as it is, is not to blame. What I suspect happening, is that the COM object I am calling craps all over my stack frame. So here is my question. How in the world do I confirm whether that is in fact happening? Debugging across COM boundaries is something I've always wanted to avoid... but since the code runs in my own memory space, there ought to be something I can do. I do have the code for the external COM object, but its sourcebase is huge - I estimate about a week of full time work to figure out everything that's going on under the hood. So this is my worst case scenario - but basically I am looking for a good way to confirm my suspicions before diving into it. Any takers on my dilemma?

Thanks,

PO
 
I am trying to avoid that - introducing that change to such a major part of our product would require a godawful lot of modification throughout the other components that use that components - a domino effect if you know what I mean. It's not so much the cost of modifying the code that calls the object, but I shudder to think at the hundreds of man-hours of QA that will go towards assuring that nothing else broke. Of course I am not doing the QA, but still, I am trying to tread as carefully as I can here.
 

TheJet

Ars Praefectus
4,598
Subscriptor++
I've seen similar things to this, but primarily when debugging VB COM objects that call/utilize backend C++ ATL objects. Every once in a while, the C++ object's memory space will be hijacked and the pointers will be pointing at nothing-ness. As long as I keep the VB debug environment out of it (or use the debug version of the ATL library) this doesn't seem to happen.

Are you using a debug or a release build of the external library? I assume you're calling from a C++ object/program to an external C++ COM object (written in MFC/ATL??). Have you tried both? Do you get the same problem when you are _not_ debugging your main object?

I've looked all over the MS site for answers to my problems, but there is nothing to be found. And it manifests itself in such bizzare ways, up to the point where I sometimes have a problem reproducing the issue. It does seem to occur more often when there is cross-process communication involved (i.e. when process 1 creates the ATL object, then passes it to process 2).

TheJet
 

wb

Ars Legatus Legionis
25,208
Subscriptor
How in the world do I confirm whether that is in fact happening? Debugging across COM boundaries is something I've always wanted to avoid... but since the code runs in my own memory space, there ought to be something I can do. I do have the code for the external COM object, but its sourcebase is huge

Well, you can recompile the offending object with debug information, run it from the debugger with the /Automation switch (assuming it's an out-of-process object), and then debug into from your code.
 

DaisyMan

Ars Tribunus Militum
2,135
The tedious solution would be for you to create a simple out-of-process intermediary object, wherein your object creates and calls the intermediary, and the intermediary creates and calls the external object, and the intermediary then passes messages back and forth between you and the external object. Could work if the interface is set in stone already.
 
Christ, this is going to be too much work no matter how you look at it.

I am going to try DaisyMan's way first, and see where it goes. I've suspected that the debug info might be messed up, so I've tried all combinations of debug/release builds of both objects, with using dialog box output in release modes to let me know what's wrong - no luck. I would do as earl suggests, but the problem is that I can't test anything outside the general framework (i.e. the whole application), and so much stuff uses that object that any change would require slight modifications (and thus recompilation) of half the codebase. If I were to get it started on my workstation, I might, just might have it done before the end of this year...

Thanks everyone for suggestions,

PO
 

Liam

Ars Scholae Palatinae
618
Dumb question: are you CoInitialize(Ex)()ing everything wherever you need to? Are threading models set appropriately?

Write a dumb little console app to make sure you can instantiate the external (I assume by "external," you mean out-of-proc) object cleanly, then maybe throw some extra stuff in there like pointers and so on, and see if they get hosed.

Write a dumb little COM object that does nothing more than instantiate the external object, serving as kind of a "wrapper" to it. Then maybe throw some extra stuff in there like pointers and so on, and see if they get hosed.

Good luck. I hate debugging COM. Half the time, I think my program is borken because it's the external object's fault. Half the time, I think it's because I don't know what I'm doing. I'm right about 98% of the time. :D
 
Status
Not open for further replies.