I am trying to use the GetPhysicallyInstalledSystemMemory
method which is present in kernel32.dll.
It requires a single argument of the type PULONGLONG, but I have no idea how to map this into a golang variable. Here is my current attempt which results in "err: The parameter is incorrect".
Can anyone explain how to do this?
package main
import (
"fmt"
"syscall"
)
var memory uintptr
func main() {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
getPhysicallyInstalledSystemMemoryProc := kernel32.NewProc("GetPhysicallyInstalledSystemMemory")
ret, _, err := getPhysicallyInstalledSystemMemoryProc.Call(uintptr(memory))
fmt.Printf("GetPhysicallyInstalledSystemMemory, return: %+v
", ret)
fmt.Printf("GetPhysicallyInstalledSystemMemory, memory: %d
", memory)
fmt.Printf("GetPhysicallyInstalledSystemMemory, err: %s
", err)
}
PULONGLONG
parameter type translates to *uint64
memory
variable to the unsafe.Pointer
type and then to uintptr
package main
import (
"fmt"
"syscall"
"unsafe"
)
func main() {
kernel32 := syscall.NewLazyDLL("kernel32.dll")
getPhysicallyInstalledSystemMemoryProc := kernel32.NewProc("GetPhysicallyInstalledSystemMemory")
var memory uint64
ret, _, err := getPhysicallyInstalledSystemMemoryProc.Call(uintptr(unsafe.Pointer(&memory)))
fmt.Printf("GetPhysicallyInstalledSystemMemory, return: %+v
", ret)
fmt.Printf("GetPhysicallyInstalledSystemMemory, memory: %d
", memory)
fmt.Printf("GetPhysicallyInstalledSystemMemory, err: %s
", err)
}