Use COM Object from DLL without register

前端 未结 3 661
青春惊慌失措
青春惊慌失措 2020-12-08 23:00

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

相关标签:
3条回答
  • 2020-12-08 23:09

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

    0 讨论(0)
  • 2020-12-08 23:09

    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.
    0 讨论(0)
  • 2020-12-08 23:29

    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
    0 讨论(0)
提交回复
热议问题