diff --git a/com/IOPCServerList.go b/com/IOPCServerList.go index c2a3a1b..078c2b8 100644 --- a/com/IOPCServerList.go +++ b/com/IOPCServerList.go @@ -62,3 +62,16 @@ func (sl *IOPCServerList2) GetClassDetails(guid *windows.GUID) (*uint16, *uint16 } return ppszProgID, ppszUserType, ppszVerIndProgID, nil } + +func (sl *IOPCServerList2) CLSIDFromProgID(szProgID string) (*windows.GUID, error) { + var clsid windows.GUID + pProgID, err := syscall.UTF16PtrFromString(szProgID) + if err != nil { + return nil, err + } + r0, _, _ := syscall.SyscallN(sl.Vtbl().CLSIDFromProgID, uintptr(unsafe.Pointer(sl.IUnknown)), uintptr(unsafe.Pointer(pProgID)), uintptr(unsafe.Pointer(&clsid))) + if r0 != 0 { + return nil, syscall.Errno(r0) + } + return &clsid, nil +} diff --git a/opcserver.go b/opcserver.go index 3067956..bd5bb61 100644 --- a/opcserver.go +++ b/opcserver.go @@ -32,11 +32,17 @@ func Connect(progID, node string) (opcServer *OPCServer, err error) { if !com.IsLocal(node) { location = com.CLSCTX_REMOTE_SERVER } - clsid, err := windows.GUIDFromString(progID) + iCatInfo, err := com.MakeCOMObjectEx(node, location, &com.CLSID_OpcServerList, &com.IID_IOPCServerList2) + if err != nil { + return nil, err + } + defer iCatInfo.Release() + sl := &com.IOPCServerList2{IUnknown: iCatInfo} + clsid, err := sl.CLSIDFromProgID(progID) if err != nil { return nil, err } - iUnknownServer, err := com.MakeCOMObjectEx(node, location, &clsid, &com.IID_IOPCServer) + iUnknownServer, err := com.MakeCOMObjectEx(node, location, clsid, &com.IID_IOPCServer) if err != nil { return nil, err }