Skip to content

Commit

Permalink
Merge pull request ropnop#3 from mec07/remove-must
Browse files Browse the repository at this point in the history
Remove must from go-clr.go
  • Loading branch information
Ne0nd0g authored Nov 10, 2022
2 parents cb41266 + d57278d commit ce145f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
20 changes: 15 additions & 5 deletions go-clr.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,26 @@ func ExecuteDLLFromDisk(targetRuntime, dllpath, typeName, methodName, argument s
}

pDLLPath, err := syscall.UTF16PtrFromString(dllpath)
must(err)
if err != nil {
return
}
pTypeName, err := syscall.UTF16PtrFromString(typeName)
must(err)
if err != nil {
return
}
pMethodName, err := syscall.UTF16PtrFromString(methodName)
must(err)
if err != nil {
return
}
pArgument, err := syscall.UTF16PtrFromString(argument)
must(err)
if err != nil {
return
}

ret, err := runtimeHost.ExecuteInDefaultAppDomain(pDLLPath, pTypeName, pMethodName, pArgument)
must(err)
if err != nil {
return
}
if *ret != 0 {
return int16(*ret), fmt.Errorf("the ICLRRuntimeHost::ExecuteInDefaultAppDomain method returned a non-zero return value: %d", *ret)
}
Expand Down
8 changes: 0 additions & 8 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package clr
import (
"bytes"
"fmt"
"log"
"strings"
"unicode/utf16"
"unsafe"
Expand All @@ -25,13 +24,6 @@ func checkOK(hr uintptr, caller string) error {
}
}

// must forces the program to exit if there is an error using the log.Fatal command
func must(err error) {
if err != nil {
log.Fatal(err)
}
}

func utf16Le(s string) []byte {
enc := unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM).NewEncoder()
var buf bytes.Buffer
Expand Down

0 comments on commit ce145f5

Please sign in to comment.