-1

I need create a module that allowed to dynamically load different versions same DLL and create COM-object.

As example, on computer might be installed 3 different versions 1C:Enterprise, its COM-objects store in this DLL (C++):

C:\Program Files (x86)\1cv8\8.3.4.389\bin\comcntr.dll
C:\Program Files (x86)\1cv8\8.3.3.156\bin\comcntr.dll
C:\Program Files (x86)\1cv8\8.3.3.322\bin\comcntr.dll

And it's all the same COM-object - "v83.ComConnector".

Is there any way to create 3 Com-object at same time in my application?

I try to use "Assembly.LoadFrom" and LoadLibrary from kernel32.dll, but it doesn't work.

Why I need to use different versions? - very often on 1 physical server working more than 1 version of 1C-server (and all of it have not the same version number) - for Russian developer who work with 1C it is normal. I can not migrate all application to the same version. So I need to connect via COM-object to different 1C-servers. But I can not do it using just one COM-object - version of the COM object and the server must be equal.

Alex
  • 1
  • 1
  • Does the interface you are trying to load all have the same GUID for the separate versions? (Also `Assembly.LoadFrom` can only used when loading managed DLLs, it has nothing to do with COM nor unmanaged code). What are you trying to do that you need to load multiple versions of the same COM DLL? – Scott Chamberlain Jan 20 '14 at 20:58
  • Yes, they all have the same COM GUID. – Alex Jan 20 '14 at 21:06
  • 1
    This such a odd request, why are you trying to load the same COM object from several installed versions? Please [edit your question](http://stackoverflow.com/posts/21243948/edit) and provide more context. There are solutions, but which one depends on what you are attempting to do with the objects. – Scott Chamberlain Jan 20 '14 at 21:07
  • I add a little more information. – Alex Jan 20 '14 at 21:30
  • You need Registration Free COM Interop because you are using multiple of the same com object with the same GUID, see this post for more information http://stackoverflow.com/questions/9586000/reg-free-com-interop-with-c-possible – Scott Chamberlain Jan 20 '14 at 21:39

1 Answers1

0

Please note, this answer indicates that it is feasible, but please examine your business case prior to performing this process.

In order to do this, you cannot be enforcing binary compatibility between the versions. Enforcing binary compatibility will ensure the CLSID is identical between versions and you will be unable to run multiple versions on the same machine simultaneously. For this solution to be feasible, you must ensure that each version has a unique CLSID.

Each component will have to have a different CLSID. Also, each will need to have it's own distinct name when running in COM+. This is tricky to achieve because I assume you are not changing the interface name to include version information. It is possible to do this however, with a registry modification.

First, you will need to install version 1 of the component. Then perform the registry modification.

Open regedit.

Export keys pertaining to your component into a single .reg file. Look in the following locations and export all matches you find. The CLSID keys to export will be in one of two different locations depending on the version of your OS.

HKEY_CLASSES_ROOT\<your component>
HKEY_LOCAL_MACHINE\Software\Classes\<your component>

HKEY_LOCAL_MACHINE\Software\Classes\<your component CLSID>
- or -
HKEY_LOCAL_MACHINE\Software\Classes\Wow6432Node\CLSID\<your component CLSID>

Then in the .reg file, rename that legacy component to indicate version information. Important: do not change the CLSID. Also, point the path to where the DLL will exist on your machine.

After the .reg file is updated, run it.

Repeat this process for each version.

Update

I also found this link that seems to address the specific component you are referring to. It is in russian, but google translate does a good job of translation.

http://infostart.ru/public/200218/

Aaron Palmer
  • 8,912
  • 9
  • 48
  • 77
  • Unfortunately, it doesn't work. When you first time change registry - it works. Com-object was created from correct version of DLL. But next when you change registry - com-object was created from first registered DLL. I think it about cache, but how to change this behavior? – Alex Jan 20 '14 at 23:24
  • Are you creating them via late-binding? – Aaron Palmer Jan 21 '14 at 14:14
  • Yes - `Dim O = Type.GetTypeFromProgID("V83.COMConnector") Dim obj As Object = Activator.CreateInstance(O) Dim b = Obj.ConnectAgent("localhost")` – Alex Jan 22 '14 at 01:03
  • The goal would be to get three different versions of `V83.COMConnector` in COM+ under different component names. Ie: `V83.COMConnector1`, `V83.COMConnector2`, `V83.COMConnector3`. That's what the registry modification would do. – Aaron Palmer Jan 22 '14 at 15:04