Skip to main content

2.4. Creating / Releasing COM component

2.4. Creating / Releasing COM component

Generally, when you use COM component, beforehand you have to register the component to the system. You can do this with below command in command-line window.

 

registering

regsvr32 HRRpcProxy.dll

unregistering

regsvr32 u HRRpcProxy.dll

 

But, the sample program provide a function named CreateInstanceFromInst(). With this function, you can create unregistered COM component and query the interface you want. If you use this way, you need to do LoadLibrary(HRRpcProxy.dll) on you own. Refer to the source code related to this function.

(This sample shows loading unregistered COM component. And of course, you can register the component, and use COM API function ::CoCreateInstance( ) to get the interface you want.)

// ------------------------------------------

// DLL dynamic linking

strPathFName = "HRRpcProxy.dll";

if(h_module_ = LoadLibrary(strPathFName) == NULL) {

             // error handling..

             return;

}

 

// ------------------------------------------

// create COM component instance & get interface

 

// IBase

HRESULT hr = CreateInstanceFromInst(h_module_, hr_rpc_proxy::CLSID_Base

                                        , hr_rpc_proxy::IID_IBase, (void*)&p_base_);

if(FAILED(hr) {

             // error handling..

             return;

}

 

p_base_->Release();

 

FreeLibrary(h_module_);