1

We have a C++ project that exposes some classes via COM Automation and thus has an IDL file.

Whenever we added new functions to the classes in the IDL (without changing the UUID), the other C++ projects that use the classes (but not the new functions) need to be rebuilt with the new IDL or they will crash but the other VB6 ActiveX projects don't crash.

Why do we need to rebuild the C++ projects but VB projects are okay?

Afriza N. Arief
  • 7,696
  • 5
  • 47
  • 74
  • 1
    Are your C++ projects using those C++ classes directly, by any chance (as opposed to working via COM interfaces)? Show some code demonstrating exactly how your C++ client gets an instance of the server and calls one method on it. – Igor Tandetnik Apr 11 '14 at 01:57

1 Answers1

5

At a guess, you're probably defining your objects in VB as just Objects, something like this:

Dim YourObject as Object
Set YourObject = CreateObject("YourComponent.YourObject")

If so, you're forcing VB to go through the automation interface (IDispatch). Basically, it doesn't know what type you're going to assign to YourObject until run-time, so it has to invoke methods on that object via IDispatch::Invoke. To do that, it looks up all the information it needs for an invocation from the object itself at run time.

By contrast, your C++ code is probably early-bound, which means offsets into the COM object's vtable are compiled directly into your code. In that case, when/if you change the code so those offsets aren't valid any more, the code will fail horribly.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111