views:

195

answers:

3

I have a C# Visual Studio 2008 project and I want use a COM interop XXXXLib (XXXX.dll).

Of course I have to add reference to %windir%\system32\xxxx.dll before, and VS will add Interop.xxxx.dll to the project folder, and now I have to distribute this 200 KB library with my simple 4 KB application.

But, now I know that PCs don't have XXXXLib or don't want use it. And in my application .NET needs check if exists COM in clients.

If COM does not exist on client's PCs, I want my application not to fail. I think I need not to reference the Interop, and use reflection for loading the interop.xxxx.dll, or another solution.

Other secondary issue, how do I check if COM exists in on client computers?

Do you have any good sample code?

I ask for gurus, for the best solution and I will give all my love to gurus.

A: 

You should distribute that dll with your app, make sure to register it properly if necessary. IF your app can work without that dll, than try to load it, and if fails... continue with execution. if not.. you must install it with your app.

Dani
Thanks mister. For any clients PC, I canNOT register xxxx.dll (rights access, etc), and for those PCs, my app needs work without xxxx.dll. If in development environment add References in my csproj, in execution environment (for those PCs) fails my app, isn't?. I need flexibility in my app, using xxxx.dll and not using xxxx.dll, and check if exists COm in clients, and use xxxx.dll in that case. If NOT exists my app works without xxxx.dll.
A: 

The best solution is to add is to add xxxx.dll in your distribuation package and work with it.

If this is an approach that is ok to you - you can try wix to make the installer.

Svetlozar Angelov
Thanks mister. For any clients PC, I canNOT register xxxx.dll (rights access, etc), and for those PCs, my app needs work without xxxx.dll. If in development environment add References in my csproj, in execution environment (for those PCs) fails my app, isn't?
+1  A: 

Instead of using the code generated by Visual Studio (that may always be executed) you should do the same conditionally in your own code. Transform your code to do so.

I have used such an approach to only require one out of three COM components (from 3 different vendors) to be installed on the client computer (COM components for spectrum display for use with mass spectrometry data).

The code I use can found here, near "Add spectrum control, but only the one corresponding ...". The function addSpectrumControl() can be found here.

You can check for existence of a COM component installed on the client computer by wrapping the call to creating an instance of the COM component in a try-catch block. If it fails an exception will be thrown that will then be catched in the catch block. You then know it is not installed (or not registered or some other error). In any case you then know it can not be used.

Peter Mortensen
I can see clear that solution... any reference of a wrapping if theCOM doesnt installed in client computer fails, isnt'??? regards
@alhambra eidos kiquenet: I am not sure if I understand this correctly, but I think this has to do with references at compile time, not at install time at a client computer. @ALL: can someone help out?
Peter Mortensen