Thanks 在 2017年12月16日星期六 UTC+8上午1:47:33,Jake Montgomery写道: > > I have not called a Windows API from go before, so there may be other > problems with your code. But looking at WlanEnumInterfaces documentation > <https://msdn.microsoft.com/en-us/library/windows/desktop/ms706716(v=vs.85).aspx> > > the last parameter is *not *a pointer to a pointer to a > WLAN_INTERFACE_INFO_LIST, it is a pointer to a PWLAN_INTERFACE_INFO_LIST. > So, in C terms. it is a *WLAN_INTERFACE_INFO_LIST***. In other words, you > should be passing it a *pointer *to a uintptr, then dereferencing it > twice to get the actual list. > > (Also, don't forget to call *WlanFreeMemory* when you are done.) > > Good Luck > - Jake > > On Thursday, December 14, 2017 at 11:15:52 PM UTC-5, 流沙 wrote: >> >> API Address:https://msdn.microsoft.com/en-us/library/ms706716(VS.85).aspx >> >> Code: >> >> package main >> >> // #define WIN32_LEAN_AND_MEAN >> // #include <windows.h> >> >> import ( >> "fmt" >> "syscall" >> "unsafe" >> "C" >> ) >> var ( >> wlankernal,_ = syscall.LoadLibrary("Wlanapi.dll") >> wlanhandle,_ = syscall.GetProcAddress(wlankernal,"WlanOpenHandle") >> wlanclosehandle,_ = syscall.GetProcAddress(wlankernal,"WlanCloseHandle") >> wlanenumInterfaces,_ = >> syscall.GetProcAddress(wlankernal,"WlanEnumInterfaces") >> wlangetprofile,_ = syscall.GetProcAddress(wlankernal,"WlanGetProfileList") >> ) >> type ulong int32 >> >> type WLAN_INTERFACE_INFO struct{ >> InterfaceGuid syscall.GUID >> strInterfaceDescription string >> isState uint >> } >> >> type WLAN_INTERFACE_INFO_LIST struct { >> NumberOfItems uint32 >> Index uint32 >> InterfaceInfo WLAN_INTERFACE_INFO >> } >> >> type WLAN_PROFILE_INFO struct{ >> ProfileName C.char >> Flags ulong >> } >> >> type WLAN_PROFILE_INFO_LIST struct{ >> NumberOfItems ulong >> Index ulong >> ProfileInfo WLAN_PROFILE_INFO >> } >> >> func abort(funcname string, err error) { >> panic(fmt.Sprintf("%s failed: %v", funcname, err)) >> } >> >> //打开一个WLAN句柄 >> func WlanOpenHandle() (result uint32) { >> negotiated_version := uint32(0) >> client_handle := uint32(0) >> dwClientVersion := uint32(2) >> var nargs uintptr = 4 >> ret,_,callErr := syscall.Syscall6(uintptr(wlanhandle), >> nargs, >> uintptr(dwClientVersion), >> 0, >> uintptr(unsafe.Pointer(&negotiated_version)), >> uintptr(unsafe.Pointer(&client_handle)), >> 0, >> 0, >> ) >> if ret != 0{ >> abort("StartWLANHandleError", callErr) >> return >> } >> result = uint32(client_handle) >> return >> } >> >> //关闭WLAN句柄 >> func WlanCloseHandle() { >> var nargs uintptr = 2 >> handle :=WlanOpenHandle() >> ret,_,callErr := syscall.Syscall(uintptr(wlanclosehandle), >> nargs, >> uintptr(handle), >> 0, >> 0, >> ) >> if ret !=0{ >> abort("CloseHandleError",callErr) >> return >> } >> fmt.Println("WlanCloseHandle Successful") >> } >> >> >> func main() { >> defer syscall.FreeLibrary(wlankernal) >> var nargs uintptr = 3 >> handle :=WlanOpenHandle(); >> var wlan_interface_info WLAN_INTERFACE_INFO_LIST; >> ret,_,callErr := syscall.Syscall(uintptr(wlanenumInterfaces), >> nargs, >> uintptr(handle), >> 0, >> uintptr(unsafe.Pointer(&wlan_interface_info)), >> ) >> if ret !=0{ >> abort("WlanEnumInterfacesError",callErr) >> return >> } >> WlanCloseHandle() >> fmt.Println(ret) >> fmt.Println(wlan_interface_info) >> } >> >> >> >> wlan_interface_info returns a value of {7306176 0 {{0 0 0 [0 0 0 0 0 0 0 >> 0]} 0}} >> This value seems to be wrong! >> May I ask how to solve this problem? >> >>
-- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.