gpt4 book ai didi

c++ - 在golang调用DLL?

转载 作者:数据小太阳 更新时间:2023-10-29 03:42:31 24 4
gpt4 key购买 nike

package main

import (
"fmt"
"syscall"
"unsafe"
)

const (
PROCESS_QUERY_INFORMATION = 1 << 10
PROCESS_VM_READ = 1 << 4
)

//defind a struct
type PROCESS_MEMORY_COUNTERS struct {
cb uint32
PageFaultCount uint32
PeakWorkingSetSize uint64
WorkingSetSize uint64
QuotaPeakPagedPoolUsage uint64
QuotaPagedPoolUsage uint64
QuotaPeakNonPagedPoolUsage uint64
QuotaNonPagedPoolUsage uint64
PagefileUsage uint64
PeakPagefileUsage uint64
}

func main() {
//get Process Handle
current, err := syscall.OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, false, 728)
if err != nil {
return
}
//call psapi.ll
psapi := syscall.NewLazyDLL("psapi.dll")
var process PROCESS_MEMORY_COUNTERS
process.cb = uint32(unsafe.Sizeof((process)))
GetProcessMemoryInfo := psapi.NewProc("GetProcessMemoryInfo")
_, _, err = GetProcessMemoryInfo.Call(uintptr(current), uintptr(unsafe.Pointer(&process)), unsafe.Sizeof(&process))
if err != nil {
fmt.Println(err)
} else {
fmt.Println(process)
}
}

报告这个错误:

The data area passed to a system call is too small

最佳答案

unsafe.Sizeof(&process) 返回指针的大小——变量process占用的内存地址。

我想你想为此使用 unsafe.Sizeof(process)

关于c++ - 在golang调用DLL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36326870/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com