Knowledge Base Nr: 00064 Create_COM_Object_via_DCOM.cpp - http://www.swe-kaiser.de
Downloads:
Win32: example of creating a COM object via DCOM
(the COM object must be configured on server machine)
//#include <lmcons.h> ???
#import "MyObject.tlb" no_namespace named_guids
//lpszServer examples: "192.168.32.17", "Pentium2"
HRESULT CMyClass::StartDCOMconnection(LPCSTR lpszServer
, IMyObjectDCOM* pMyObject
, BOOL* bSuccess)
{
HRESULT hr;
pMyObject = NULL;
*bSuccess = FALSE;
try
{
MULTI_QI mq;
COSERVERINFO csi, *pcsi=NULL;
WCHAR wsz [MAX_PATH];
//machine-name for DCOM
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, lpszServer, -1, wsz, MAX_PATH);
memset(&csi, 0, sizeof(COSERVERINFO));
csi.pwszName = wsz;
pcsi = &csi;
//create a remote instance of the object on the 'szServerName' machine
mq.pIID = &IID_IDCOM;
mq.pItf = NULL;
mq.hr = S_OK;
hr = CoCreateInstanceEx(__uuidof(MyObject), NULL, CLSCTX_SERVER, pcsi, 1, &mq);
if (FAILED(hr))
_com_issue_error(hr);
pMyObject = (IMyObjectDCOM*) mq.pItf;
*bSuccess = TRUE;
}
catch (_com_error& /* e */)
{
ASSERT(FALSE);
}
return hr;
}