如何使用Windows DLL方法

如何使用Windows DLL方法,windows,go,Windows,Go,我正在尝试使用kernel32.dll中的方法 它需要一个类型为的参数,但我不知道如何将其映射到golang变量。以下是我当前的尝试,它导致错误:参数不正确 有人能解释一下怎么做吗 package main import ( "fmt" "syscall" ) var memory uintptr func main() { kernel32 := syscall.NewLazyDLL("kernel32.dll") getPhysicallyInstall

我正在尝试使用kernel32.dll中的方法

它需要一个类型为的参数,但我不知道如何将其映射到golang变量。以下是我当前的尝试,它导致错误:参数不正确

有人能解释一下怎么做吗

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\n", ret)
    fmt.Printf("GetPhysicallyInstalledSystemMemory, memory: %d\n", memory)
    fmt.Printf("GetPhysicallyInstalledSystemMemory, err: %s\n", err)

}
PULONGLONG参数类型转换为*uint64 必须将内存变量的地址强制转换为类型,然后再转换为uintpttr
如果你能留下一条评论来解释否决投票的原因,那就很有帮助了。我可能也会这样做。谢谢你,蒂姆。我曾经有过类似的事情,但没有不安全的指针,我想我现在明白了,但仍然在努力弄清楚如何为所有类型的人做到这一点,看看我现在将如何引用一个类——我想你不知道关于c/go绑定的任何好教程
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\n", ret)
    fmt.Printf("GetPhysicallyInstalledSystemMemory, memory: %d\n", memory)
    fmt.Printf("GetPhysicallyInstalledSystemMemory, err: %s\n", err)

}