gpt4 book ai didi

winapi - 为什么WNetOpenEnum会得到ERROR_INVALID_ADDRESS(487)结果?

转载 作者:行者123 更新时间:2023-12-03 11:39:23 30 4
gpt4 key购买 nike

试图在Rust上使用WINAPI库https://docs.microsoft.com/en-us/windows/win32/wnet/enumerating-network-resources重写

let dw_result: DWORD;
let mut h_enum: LPHANDLE = null_mut();
let mut lpnr_local: LPNETRESOURCEW = null_mut();


dw_result = WNetOpenEnumW(RESOURCE_GLOBALNET, // all network resources
RESOURCETYPE_ANY, // all resources
0, // enumerate all resources
lpnr_local, // NULL first time the function is called
h_enum);
if dw_result != WN_NO_ERROR {
println!("WnetOpenEnum failed with error {:?}\n", dw_result);
}
但是此代码将487分配给dw_result,这意味着ERROR_INVALID_ADDRESS
而且我不明白什么是错的

最佳答案

我猜您怀疑LPHANDLEHANDLE之间的区别。

LP stands for Long Pointer. It's a pointer to a handle.


如果要使用 LPHANDLE,请给它一个合法地址。
像这样:(C++)
HANDLE ph;
LPHANDLE hEnum = &ph;
或者只是使用 HANDLE
let mut h_enum: HANDLE;
...
dw_result = WNetOpenEnumW(RESOURCE_GLOBALNET, // all network resources
RESOURCETYPE_ANY, // all resources
0, // enumerate all resources
lpnr_local, // NULL first time the function is called
&h_enum);
相关: LPHANDLE vs. HANDLE

关于winapi - 为什么WNetOpenEnum会得到ERROR_INVALID_ADDRESS(487)结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63556257/

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