Is activation without registration possible for COM EXE servers (outside the process)?

I know that we can use CoLoadLibrary and DllGetClassObject to get the IClassFactory interface and get the COM component interface without registering the DLL.

But what about the COM component in the EXE? Is there a way that I can get the interface of a COM component from an EXE type COM server by simply providing a different file path?

+5
source share
3 answers

If you are using a real registration free COM , you should be able to get this to work both inside and outside the domain, proc COM objects.

Sharptooth, COM. , , COM . , , COM, , .

+3

, . COM- COM- out-proc. CoInitialize(), CoCreateInstance(), CoGetClassObject().

, - CoLoadLibrary(), DllGetClassObject() - - COM-, , , , ( STA/MTA). , DLL . COM- out-proc - COM.

+2

COM- .

, , EXE COM DLL, EXE DLL. , , , .

interface ILoadedObject
{
    HRESULT GiveObject(IUnknown *pObj);
};

DLL , EXE , , EXE .

IUnknown: , Release , QueryInterface IUnknown .

, EXE , ; COM EXE, Windows. OLE; .

, , EXE , . EXE :

interface IComponent;

interface IEnvironment : IUnknown
{
    HRESULT CreateInstance(REFCLSID clsid, IComponent **ppNew);
}

:

interface IComponent : IUnknown
{
    HRESULT SetEnvironment(IEnvironment *pEnv);
}

, , EXE , CreateInstance :

HRESULT Env::CreateInstance(REFCLSID clsid, IComponent **ppNew)
{
    HRESULT hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
                     __uuidof(IComponent), (void **)&ppNew);
    if (FAILED(hr))
        return hr;

    (*ppNew)->SetEnvironment(this);
    return S_OK;
}

, , "" . ( ) . ( ), EXE :

, :

// inside some component:
HRESULT Comp::SetEnvironment(IEnvironment *e)
{
    m_env = e; // using a smart pointer for ref-counting
    return S_OK;
}

// in some method of the component

ComPtr<IComponent> button;
m_env->CreateInstance(CLSID_Button, &button);

// now query button for more useful interface...

Therefore, whenever a component is created, the environment (defined in the EXE) can precisely control how the implementation of the component is implemented. Each creation takes place through an exe.

This is sometimes called "dependency injection" or "control inversion."

+1
source

All Articles