现场OPC客户端无法获取远程OPC Server列表,也无法连接OPC Server,经查调用CoCreateInstanceEx()创建IID_IOPCServerList接口正常,但调用IOPCServerList->EnumClassesOfCategories()时返回0x80070532错误,可是用PI的OPC-Tool测试OPC Server的各项操作正常,于是被迫周末加班一天,发现是未对OPC客户端的进程进行安全初始化造成的:
1
2
3
4
5
6
7
8
9
10
11 |
HRESULT
hr = ::CoInitializeSecurity( NULL, // points to security descriptor -1, // count of entries in asAuthSvc NULL, // array of names to register NULL, // reserved for future use RPC_C_AUTHN_LEVEL_NONE, // the default authentication level for proxies RPC_C_IMP_LEVEL_IMPERSONATE, // the default impersonation level for proxies NULL, // used only on Windows 2000 EOAC_NONE, // additional client or server-side capabilities NULL // reserved for future use ); |
该代码只需要加入到CxxxxApp::InitInstance()中即可。
总结:
原文:http://www.cnblogs.com/heqing/p/3562031.html