Skip to content

Commit

Permalink
Merge pull request #7 from huskar-t/fix/remote
Browse files Browse the repository at this point in the history
fix: connect remote
  • Loading branch information
huskar-t authored May 29, 2024
2 parents 8016e64 + b9b1d02 commit 3c352b9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions com/IOPCServerList.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 8 additions & 2 deletions opcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 3c352b9

Please sign in to comment.