I need to write a program that uses some COM objects, accessed from the python comtypes package. I use the clsid and/or progid to create and use them. These objects are provided by a third party, and normally they are installed with a normal installer (setup.exe or MSI file).
Let's suppose that these DLL files have a license that allows me to ship them together with my program. Is it possible to load these DLL files into memory, and use them from a portable app without actually registering them? Or alternatively, can I register them from my program?
A related question is this: how to determine the chain of DLL files that are needed to create a given COM object? (Other than trial and error.)
Background: in reality, there are multiple libs and the main problem is that I do not want the users to run 4 different installers before they can start the actual program. That would be too difficult for an average user.
You're asking a lot of questions here. There are a lot of ways to accomplish what you're trying to accomplish, and it's hard to answer such a broad set of questions. If you have specific questions on how to do a specific thing, please start new posts for those.
That said, I will try to give you some information to help you figure out what you need/want to do.
Yes. There are several ways, depending on the needs of the COM DLL and the platform you're using. However, some options won't always work, and other options are very challenging.
DllGetClassObject
- In some cases, depending on the COM object you're trying to load, you can just load the DLL, call the DllGetClassObject
function directly, and use the returned IClassFactory
to create your object. This is the easiest way -- if it works. If the class you create requires that the DLL be registered (maybe it does a CoCreateInstance
internally, or maybe it needs proxy support), this won't work for you. To determine if this will work, it's either trial-and-error, or you have to ask the developer of the COM DLL.Yes. There are a few ways. However, you are likely to run into security issues here -- typically, COM components register themselves in HKEY_LOCAL_MACHINE
, and you typically need admin rights to write here. Some COM components/installers are designed to register themselves in HKEY_CURRENT_USER
, which would get around the security thing. However, you may have no control over where a component registers itself, and even if you do, registering in HKEY_CURRENT_USER
isn't a perfect solution.
regsvr32.exe
- One option is to programmatically invoke regsvr32.exe
on the DLL.DllRegisterServer
or DllInstall
- If a COM DLL can be registered with regsvr32.exe
, then it has at least one of these functions exported. You can load the DLL manually and call these functions just like regsvr32.exe
does. DllInstall
is less common than DllRegisterServer
. If DllInstall
is present, it may give you the option of installing in HKEY_CURRENT_USER
. If not, you have to just do whatever DllRegisterServer
does, since there are no options you can provide to that function.HKEY_LOCAL_MACHINE
/HKEY_CURRENT_USER
issue -- you can write them wherever you like (but HKEY_LOCAL_MACHINE
still probably requires admin rights).regedit.exe
- Another way to write the registry values yourself is to store them in a .reg
file and call regedit.exe
to merge them.Ideally, the developer of that DLL knows and can tell you. That's the only way that's truly fool-proof.
CoCreateInstance
to create some third-party COM object, and since this is something that is only expressed in source code, there is no metadata on the DLL that will help you find these dependencies.LoadLibrary
directly, there is no way for you to determine the dependency from the outside.If you know exactly what files to write, where to write them and what registry settings (etc) need to be applied, you can do all of that yourself. For some dependencies, it can be easier to just include the third-party installer in your installer and just execute it silently. Many installers support a silent mode for just this reason. A good example of this is the Visual C++ runtime (msvcrt*.dll) -- many applications need this dependency, and many installers just include Microsoft's installer as a part of their distribution, and the primary installer just calls the secondary installers silently.