Skip to content

Commit

Permalink
fix: correct api usage
Browse files Browse the repository at this point in the history
  • Loading branch information
huskar-t committed Jun 17, 2024
1 parent c9ed63e commit 4ca451c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions com/com.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com

import (
"errors"
"strings"
"syscall"
"unsafe"

Expand Down Expand Up @@ -184,16 +185,18 @@ func SysFreeString(v *uint16) (err error) {
}

func MakeCOMObjectEx(hostname string, serverLocation CLSCTX, requestedClass *windows.GUID, requestedInterface *windows.GUID) (*IUnknown, error) {
requestedServerInfo := COSERVERINFO{
PwszName: windows.StringToUTF16Ptr(hostname),
PAuthInfo: nil,
}
reqInterface := MULTI_QI{
PIID: requestedInterface,
PItf: nil,
Hr: 0,
}
err := CoCreateInstanceEx(requestedClass, nil, serverLocation, &requestedServerInfo, 1, &reqInterface)
var serverInfoPtr *COSERVERINFO = nil
if serverLocation != CLSCTX_LOCAL_SERVER {
serverInfoPtr = &COSERVERINFO{
PwszName: windows.StringToUTF16Ptr(hostname),
}
}
err := CoCreateInstanceEx(requestedClass, nil, serverLocation, serverInfoPtr, 1, &reqInterface)
if err != nil {
return nil, err
}
Expand All @@ -204,7 +207,14 @@ func MakeCOMObjectEx(hostname string, serverLocation CLSCTX, requestedClass *win
}

func IsLocal(host string) bool {
return host == "" || host == "localhost" || host == "127.0.0.1"
if host == "" || host == "localhost" || host == "127.0.0.1" {
return true
}
name, err := windows.ComputerName()
if err != nil {
return false
}
return strings.ToLower(name) == strings.ToLower(host)
}

// Initialize initialize COM with COINIT_MULTITHREADED
Expand Down

0 comments on commit 4ca451c

Please sign in to comment.