windows: add (*DLL).FindProcByOrdinal
Change-Id: I0b0ef2c62994fad4d89bf15c8c6c95fa660190c3
GitHub-Last-Rev: 379ab4a0f5a6ce8ee4b9eb234312a56e5cd07b72
GitHub-Pull-Request: golang/sys#69
Reviewed-on: https://go-review.googlesource.com/c/sys/+/227439
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
diff --git a/windows/syscall_test.go b/windows/syscall_test.go
index 7e28834..af3ff32 100644
--- a/windows/syscall_test.go
+++ b/windows/syscall_test.go
@@ -79,3 +79,24 @@
t.Fatalf("System Windows directory does not end in windows: %s", d2)
}
}
+func TestFindProcByOrdinal(t *testing.T) {
+ // Attempt calling shlwapi.dll:IsOS, resolving it by ordinal, as
+ // suggested in
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/bb773795.aspx
+ dll, err := windows.LoadDLL("shlwapi.dll")
+ if err != nil {
+ t.Fatalf("Failed to load shlwapi.dll: %s", err)
+ }
+ procIsOS, err := dll.FindProcByOrdinal(437)
+ if err != nil {
+ t.Fatalf("Could not find shlwapi.dll:IsOS by ordinal: %s", err)
+ }
+ if procIsOS.Name != "#437" {
+ t.Fatalf("Proc's name is incorrect: %s,expected #437", procIsOS.Name)
+ }
+ const OS_NT = 1
+ r, _, _ := syscall.Syscall(procIsOS.Addr(), 1, OS_NT, 0, 0)
+ if r == 0 {
+ t.Error("shlwapi.dll:IsOS(OS_NT) returned 0, expected non-zero value")
+ }
+}