描述:
#include "stdafx.h"
#define _WIN32_DCOM
#include "windows.h"
#include "stdio.h"
#include "stdlib.h"
#include "comdef.h"
static const CLSID GUID_test030626={0x0A4029E2,0x6CC7,0x4AD2,{0x9A,0xD3,0x5E,0xF9,0x6C,0xE2,0x80,0xEF}};
const IID clientIID={0x3D036AB3,0x1FCA,0x44D7,{0xB7,0xE3,0x95,0xA2,0x96,0x2C,0x07,0x8F}};
LPDATAOBJECT *lpd;
WCHAR *wServerName=L"172.16.0.139";
int main(int argc, char* argv[])
{
COSERVERINFO si;
STGMEDIUM stg;
FORMATETC fe ;
fe.cfFormat = CF_TEXT ;
fe.ptd = NULL ;
fe.tymed = TYMED_HGLOBAL ;
fe.dwAspect = DVASPECT_CONTENT ;
fe.lindex = -1 ;
TCHAR* pErrMsg=NULL;
si.pwszName=L"172.16.0.139";
si.dwReserved1=0;
si.dwReserved2=0;
si.pAuthInfo=NULL;
MULTI_QI mqi[1];
mqi[0].pIID =&clientIID;
mqi[0].pItf=NULL;
mqi[0].hr=0;
HRESULT hr=CoInitializeEx(NULL,0);
hr=CoCreateInstanceEx(
GUID_test030626,
NULL,
CLSCTX_REMOTE_SERVER,
&si,
1,
mqi);
if(hr==REGDB_E_CLASSNOTREG)
{
printf("REGDB_E_CLASSNOTREG \n");
}
if(hr==CLASS_E_NOAGGREGATION)
{
printf("CLASS_E_NOAGGREGATION \n");
}
if(hr==CO_S_NOTALLINTERFACES)
{
printf("CO_S_NOTALLINTERFACES \n");
}
if(hr==E_NOINTERFACE)
{
printf("E_NOINTERFACE \n");
}
if(hr!=S_OK)
{
MessageBox(NULL,"Couldnot create object","Error",MB_ICONSTOP);
printf("hr=%ld",hr);
::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,NULL,hr,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),
(LPTSTR)&pErrMsg,0,NULL);
printf("%s",pErrMsg);
::LocalFree(pErrMsg);
}
else
{
lpd=(LPDATAOBJECT *)mqi[0].pItf;
///////????????????????????/////////////
//在这里如何调用DCOM接口中的方法 ????
}
return 0;
}