Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use COM Object from DLL without register

Tags:

c++

dll

com

Is it possible to use COM Object from DLL without register in C++ not managed code?

like image 534
EOG Avatar asked Jun 18 '12 17:06

EOG


People also ask

Can a DLL be used without registering it?

Yes, if it does not rely internally on other registered objects. Roman R. Roman R.

How do I register a COM object DLL?

Click Start > All Programs > Accessories and right-click on "Command Prompt" and select "Run as Administrator" OR in the Search box, type CMD and when cmd.exe appears in your results, right-click on cmd.exe and select "Run as administrator" At the command prompt, enter: REGSVR32 "PATH TO THE DLL FILE"


3 Answers

Yes, if it does not rely internally on other registered objects.

  1. You LoadLibrary the DLL
  2. You GetProcAddress its DllGetClassObject
  3. You call DllGetClassObject to obtain IClassFactory pointer for CLSID of interest
  4. You are good to go with IClassFactory::CreateInstance and instantiate the coclass
like image 172
Roman R. Avatar answered Oct 04 '22 13:10

Roman R.


You can create manifest files for the DLL and use Registration-Free COM.

like image 43
Sergey Podobry Avatar answered Oct 04 '22 12:10

Sergey Podobry


Say, the COM DLL needs to be registered, but the application doesn't have admin access rights. Here is an easy hack to register the DLL under HKEY_CURRENT_USER, which doesn't require admin rights:

  1. Use LoadLibrary to load the COM DLL.
  2. Call GetGetProcAddress to get the address of DllRegisterServer.
  3. Call RegOverridePredefKey to make the temporary registry redirects: HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER and HKEY_CLASSES_ROOT to HKEY_CURRENT_USER\Software\Classes.
  4. Call DllRegisterServer obtained in step 2.
  5. Reverse the registry redirects.
  6. Use the COM server as usual, it's now registered under HKEY_CURRENT_USER.
like image 40
noseratio Avatar answered Oct 04 '22 11:10

noseratio