在 golang 调用 DLL 上
On the golang call DLL?
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)
}
}
报告此错误:
传递给系统调用的数据区域太小
unsafe.Sizeof(&process)
返回指针的大小 — 变量 process
占用的内存地址。
我想你想用unsafe.Sizeof(process)
来做这件事。
相关文章:
- 如何安全地从 DLL 调用返回对象
- C++结构到德尔福记录dll调用
- 从 C#-DLL 调用函数的 C++ 失败
- 可视C++:XGBoost 从 DLL 调用时不起作用
- Unity3D的OpenCV dll调用导致FPS下降
- 创建一个C++DLL以从C#DLL调用方法
- 从 dll 调用 opencv 垫到 Windows 表单,图像出现故障
- 努力使用 C# 从本机 DLL 调用该方法
- WinAPI - GetLastError 在通过 COM ATL DLL 调用时始终返回 0
- 必须使用C DLL调用C#.NET方法
- 如何直接从 pdfium.dll 调用 v8 函数
- 为什么从 DLL 调用类方法需要虚拟说明符?
- VBA 中的多个 DLL 调用
- 挂钩VirtualAlloc在系统DLL调用时返回NULLPTR
- 无法从 C DLL 调用该函数
- DLL 调用涉及 strncpy() 的方法
- JNA从DLL调用C++对象-java.lang.IollegalArgumentException:Structure
- 德尔福动态DLL调用中的奇怪行为
- 从非托管 DLL 调用 UWP api
- boost::从 DLL 调用时日志格式不起作用