0

I know, we can register interfaces of COM DLL using regsvr32.exe

is any windows C++ API available, Which API will register interfaces of COM DLL.

Thanks! Vijay Kumbhani

1
  • 1
    Regsvr32.exe is about the simplest program you can think of. It uses LoadLibrary() to load the DLL and GetProcAddress() to find the DllRegisterServer export. And calls it, that's all. No api is provided because it is so simple. Commented Mar 5, 2018 at 12:37

2 Answers 2

2

All regsvr32 does is load a dll and call the DllRegisterServer function exposed by the DLL.

If you want to write your own code to do this then you need to use LoadLibrary and GetProcAddress to get a pointer to the function, and then just call it.

Sign up to request clarification or add additional context in comments.

Comments

0

Do you know the CLSID and COM dll file path? If yes, you can write them into registry with API RegCreateKeyEx/SetKeyValue/RegCreateKeyEx/..., here is a example:

[HKEY_CLASSES_ROOT\CLSID\{CLSID}\InprocServer32]
@="C:\\Windows\\System32\\oleaut32.dll"    
"ThreadingModel"="Both"

LONG lreturn = RegCreateKeyEx(
        HKEY_CLASSES_ROOT,
        _T("CLSID\${COMCLSID}"),  // subkey
        0,                        // reserved
        NULL,                     // class string (can be NULL)
        REG_OPTION_NON_VOLATILE,
        KEY_ALL_ACCESS,
        NULL,                     // security attributes
        &hKey,
        NULL                      // receives the "disposition" (is it a new or existing key)
        );
hr = __HRESULT_FROM_WIN32(lreturn);
// The default key value is a description of the object.
if (SUCCEEDED(hr))
{
    hr = SetKeyValue(hKey, NULL, _T("your description"));
}

// Create the "InprocServer32" subkey
if (SUCCEEDED(hr))
{
    const TCHAR *sServer = TEXT("InprocServer32");

    LONG lreturn = RegCreateKeyEx(hKey, sServer, 0, NULL,
        REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hSubkey, NULL);

    hr = __HRESULT_FROM_WIN32(lreturn);
}

if (SUCCEEDED(hr))
{
    hr = SetKeyValue(hSubkey, NULL, _T("${COM DLL file Path}"));
}

// Add a new value to the subkey, for "ThreadingModel" = <threading model>
if (SUCCEEDED(hr))
{
    hr = SetKeyValue(hSubkey, TEXT("ThreadingModel"), sThreadingModel);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.