发表于:2003-08-19 14:24:00
3楼
these are my example ,and you try.
IOPCServerList* pOPCServerList;
CLSID clsid;
::CLSIDFromProgID(L"OPC.ServerList.1",&clsid);
HRESULT r;
r=::CoCreateInstance(
clsid,
NULL,
CLSCTX_LOCAL_SERVER,
IID_IOPCServerList,
(void**)&pOPCServerList);
if(FAILED(r))
{
AfxMessageBox("get OPC.ServerList.1 error");
return FALSE;
}
IEnumGUID * ppenumClsid;
r=pOPCServerList->EnumClassesOfCategories(
0,
NULL,
0,
NULL,
&ppenumClsid
);
if(FAILED(r))
{
AfxMessageBox("EnumClassesOfCategories error ");
exit(1);
}
CLSID guid;
ULONG Tagsread;
CHAR str[50];
CString theString;
LPOLESTR ppszProgID;
WCHAR* ppszUserType;
r=ppenumClsid->Next(1,&guid,&Tagsread);
if(FAILED(r))
{
AfxMessageBox("next error");
}
while(Tagsread==1)
{
r=pOPCServerList->GetClassDetails(guid,&ppszProgID,&ppszUserType);
TRACE("========%x=========\n",r);
if(FAILED(r))
{
CString str;
str.Format("%ld\n",r);
AfxMessageBox(str);
break;
}
WideCharToMultiByte(0,0,ppszProgID,50,str,50,NULL,FALSE);
theString.Format("%s",str);
this->m_lbServerList.AddString(theString);
ppenumClsid->Next(1,&guid,&Tagsread);
}
ppenumClsid->Release();
pOPCServerList->Release();