kmort
kmort

Reputation: 2948

COM Object Registration--Multiple allowed?

I have two COM objects with different GUID values, but the same name. One is a newer version of the other. What happens when I register both using Name.exe /regserver? I've looked in the registry, and they both show up with the same ProgID, but their respective GUID values are different. They point to their separate locations on the hard drive. Is this a problem?

I'm trying to get the old version of a project to work alongside the new version of a project (but not running at the same time), and I think these two things are fighting.

The COM objects were created in VB6. The code that uses them is C#. They are added to their individual C# projects as references. When one is registered, I can't compile the other (nor run successfully).

What other information would be helpful while investigating this issue?

Upvotes: 2

Views: 476

Answers (3)

Hans Passant
Hans Passant

Reputation: 942207

You are violating hard COM rules. Either your replacement must be an exact match with the component you replace. Or you must generate a new version that:

  • Uses a different [Guid] for the coclass, you did that correctly.
  • Uses a different ProgId, you didn't do that. Boilerplate is to include a version number in the ProgId itself. So a Foo.Bar becomes Foo.Bar.2
  • Uses different [Guids] for the interfaces implemented by the class. This is easy to overlook since they are hidden so well in a VB6 component. Crucial however whenever the class is used from another apartment. COM needs to find the type library for the component so it knows how to marshal the interface method call. Be sure to declare your interfaces explicitly in your C# code.

The best way to double-check all this is by running OleView.exe, File + View Typelib command. That decompiles the type library content back to IDL, you will see the guids and interfaces. If you want to create an exact substitute for the old component then everything must match exactly. Exact same guids, exact same interfaces with the exact same order of methods and exact same arguments.

Upvotes: 1

MarkJ
MarkJ

Reputation: 30408

Converting my comment into an answer:

You have created a new version of a component which is not backward compatible with the old version.

You really should change the ProgID to indicate that this is effectively a new component. Client apps will have to explicitly target either the new component or the old one. People often just append a version number (e.g. 2) to the ProgId.

Upvotes: 1

tcarvin
tcarvin

Reputation: 10855

I haven't ever accessed VB6 ActiveX exes from .NET (just dlls), so this is a shot in the dark (and is weak enough to be just a comment except it is too long).

Perhaps you can create / export a .tlb each for the two VB6 components to compile your C# against. You shouldn't need the exes to compile.

Next manually add the registry entries as if they had separate Programmatic IDs (say MyComponent.ServerClass.1 and MyComponent.ServerClass.2) and then load them by name in your C#.

Upvotes: 0

Related Questions