Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reference same name/different version com object, same c# project 1

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hello
I have been searching for this answer for a while but come up short. I have a non-dot net com object with three different versions that I would like to reference in one c# application. Each version will only go against that version's database. How do I do this? The file name is also versionized (dll123.dll, dll456.dll). It looks like they share the same interop name. Is this not possible with non-dot net objects?


Thanks,
RalphTrent
 
It is possible to consume on .NET multiple versions of the same COM component.

There are a few ways I can think of.

1) Check the ProgIDs in the COM dll to find out if the COM type you want is referencing a unique progID. For example on my machine, I can see that the ADOConnectObject.ADOConnectObject (common) is registered, but along with it, I also have ...
- ADOConnectObject.ADOConnectObject.1
- ADOConnectObject.ADOConnectObject.2
- ADOConnectObject.ADOConnectObject.6 (latest)
The common progID contains a key "CurVer" which contains the guid of the latest ProgID, so that when user instantiate ADOConnectObject.ADOConnectObject, the server will actually create version 6.

For this scenario, you can call the specific "versioned" ProgID by late-binding
Code:
Type t = Type.GetTypeFromProgID("ADOConnectObject.ADOConnectObject.2");
object obj = Activator.CreateInstance(t);

2) Via late bound instantiation, you can also do the same technique as #1 by using the CLSID this time. That's the GUID of the COM type. A bit cumbersome, but works.
Code:
Type t = Type.GetTypeFromCLSID("{464EE251-FDC7-11d2-9743-00105A994F8D}");

3) Manually create the interop DLLs by using tlbimp.exe. If the output managed Dll for each COM dll does not contain a "versioned" type name other than the common type name, I suggest you change the default namespace for each COM dll.
Code:
tlbimp dll123.dll /out:interop.dll123.dll /namespace:Dll123
tlbimp dll456.dll /out:interop.dll456.dll /namespace:Dll456


var obj1 = new Dll123.MyType();
var obj2 = new Dll456.MyType();

hth [wink]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top