Use COM Object from DLL without register

前端 未结 3 668
青春惊慌失措
青春惊慌失措 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

    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.

提交回复
热议问题