mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 15:17:31 -04:00
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>
This commit is contained in:
committed by
Alex Brainman
parent
3aab700007
commit
6aff5f38e5
@@ -79,3 +79,24 @@ func TestGetWindowsDirectory(t *testing.T) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user