Jump to content

DLL calls


Recommended Posts

Hello,

Ok lets say i got this code and i want to use a dll on it:

(random one got it in micro site but i chosed it cuz its big and maybe someone could explain me the params of the DllCall() if necessery)

DWORD WINAPI WlanGetAvailableNetworkList(
_In_     HANDLE hClientHandle,
_In_     [color=blue]const[/color] GUID *pInterfaceGuid,
_In_     DWORD dwFlags,
_Reserved_ PVOID pReserved,
_Out_    PWLAN_AVAILABLE_NETWORK_LIST *ppAvailableNetworkList
);

How should my autoit Dll be so i could get the avaible network list???

$DLL = DllOpen("wlanapi.dll")
$Call = DllCall($DLL, "dword", "WlanGetAvailableNetworkList", "hwnd", "hClientHandle" , "ptr*", 1)
ConsoleWrite("Return value: " & $Call[2] & @CRLF)
DllClose($DLL)

It's really my first time using dlls so if someone want to explain something please do it in a simple way.

Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

Also why re-invent the wheel? >>

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Ok got it. So my code looks like this now and it works (dllcall to open handler as i see its not necessery and i dont understand why to use but i did...)

$DLL = DllOpen("wlanapi.dll")
$Call = DllCall($DLL, "dword", "WlanOpenHandle", "dword", 1, "ptr", 0, "dword*", 0, "hwnd*", 0)
ConsoleWrite("Return value: " & $Call[0] & @CRLF)
$Call = DllCall($DLL, "dword", "WlanGetAvailableNetworkList", "hwnd", "hClientHandle", "ptr", "pInterfaceGuid", "dword", "dwFlags", "ptr", "pReserved", "ptr*", 0)
ConsoleWrite("Return value: " & $Call[0] & @CRLF)
DllClose($DLL)

My return value of the list is 87. What does it mean? Does it get all the avaible network list on my computer atm?

I wanted to check which wifi connections that are avaible on my computer. All the values returned from the list didnt gave me any list or sth.

In second dllcall the params are written with letters and in the first one the params are written with numbers (as many functions as i check they are usually 1 or 0)

They both work though. What does the numbers represent?

I feel nothing.It feels great.

Link to comment
Share on other sites

What guinness said. The udf he pointed you to has everything your trying to learn.

Link to comment
Share on other sites

Maybe you are not understanding. I know that udf and i already have it AND use it. What i want to do is to know how does the dll works.

My example here is same as the example in the udf (almost). Why my return isnt a list with avaible network?

I feel nothing.It feels great.

Link to comment
Share on other sites

Almost? Sorry but no..

Im not pointing you to it to just use, study it. And study what msdn says about the function.

$DLL = DllOpen("wlanapi.dll")
$Call = DllCall($DLL, "dword", "WlanOpenHandle", "dword", 1, "ptr", 0, "dword*", 0, "hwnd*", 0)
ConsoleWrite("Return value: " & $Call[0] & @CRLF)

This clearly opens a handle. That handle is then used in the rest of wlan functions. the handle is in $Call[4] not $Call[0].

$Call = DllCall($DLL, "dword", "WlanGetAvailableNetworkList", "hwnd", "hClientHandle", "ptr", "pInterfaceGuid", "dword", "dwFlags", "ptr", "pReserved", "ptr*", 0)
ConsoleWrite("Return value: " & $Call[0] & @CRLF)

Ok somebody already gave a big hint to the problem. 87 = ERROR_INVALID_PARAMETER

Each parameter is for something specifc. hClienthandle does not literally take the string "hClientHandle", its for the handle that was returned from WlanOpenHandle.

You can read about what is required for all the other parameters here:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms706749(v=vs.85).aspx

Link to comment
Share on other sites

Maybe you are not understanding. I know that udf and i already have it AND use it. What i want to do is to know how does the dll works.

My example here is same as the example in the udf (almost). Why my return isnt a list with avaible network?

I'm with Beege. At no point in your first post did you mention you knew that UDF nor that you were trying to learn how to use DLLCall correctly. From what I (and everyone else) understood, you were trying to create a WiFi UDF, so I kindly pointed you a pre-existing UDF. Why don't you study the UDF because it's very clear where you are going wrong if you pay attention.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Yeah thats right i should study that UDF.

I got a question though. DllCall of the WlanGetAvailableNetworkList shouldnt return me an avaible network list?

Is this script right?

#include <WinApi.au3>
$DLL = DllOpen("wlanapi.dll")
$Call = DllCall($DLL, "dword", "WlanOpenHandle", "dword", 1, "ptr", 0, "dword*", 0, "hwnd*", 0)
ConsoleWrite("//---OpenHandle---" & @CRLF)
ConsoleWrite("Return value: " & $Call[0] & @CRLF)
ConsoleWrite("Return value: " & $Call[1] & @CRLF)
ConsoleWrite("Return value: " & $Call[2] & @CRLF)
ConsoleWrite("Return value: " & $Call[3] & @CRLF)
ConsoleWrite("Return value: " & $Call[4] & @CRLF)
Sleep(2000)
$hClientHandle = $Call[4]
$Call = DllCall($DLL, "dword", "WlanGetAvailableNetworkList", "hwnd", $hClientHandle, "ptr", 0, "dword", 0, "ptr", 1, "ptr*", 0)
ConsoleWrite("----------" & @CRLF)
ConsoleWrite("Return value: " & $Call[0] & @CRLF)
ConsoleWrite("Return value: " & $Call[1] & @CRLF)
ConsoleWrite("Return value: " & $Call[2] & @CRLF)
ConsoleWrite("Return value: " & $Call[3] & @CRLF)
ConsoleWrite("Return value: " & $Call[4] & @CRLF)
ConsoleWrite("Return value: " & $Call[5] & @CRLF)
DllClose($DLL)
Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

Hey man,

In order to call WlanGetAvailableNetworkList you need three things,

a client handle - get it through WlanOpenHandle

a pointer to you wireless cards GUID - get it through WlanEnumInterfaces

you need to specify flags

in your snippet above you only have managed to get the first item. then, you haven't given it to WlanGetAvailableNetworkList. It is expecting a valid handle, you have given it a string. edit: you've corrected this part!!

The code below shows in more detail what happens when you obtain a client handle.

local $hDLL = DllOpen("wlanapi.dll"), $aResult, $hClientHandle

;DWORD WINAPI WlanOpenHandle(
; _In_ DWORD dwClientVersion, [dword i.e. a 32 bit (unsigned) integer]
; _Reserved_ PVOID pReserved, [reserved - must be 0]
; _Out_ PDWORD pdwNegotiatedVersion, [returns a pointer to a dword. i.e. the address in memory where the dword lives]
; _Out_ PHANDLE phClientHandle [pointer to a handle]
;);

$aResult = DllCall($hDLL, "dword", "WlanOpenHandle", _
"dword", 2, _ ;IN DWORD dwClientVersion (1 for XP, 2 for Vista & up)
"ptr", 0, _ ;RSV PVOID pReserved (Must be 0)
"dword*", 0, _ ;OUT PDWORD pdwNegotiatedVersion - not an input param so specify 0. the * tells DllCall() to expect a pointer but return the data it points to. in ths case a dword.
"hwnd*", 0) ;OUT PHANDLE phClientHandle - same deal. expect a pointer, then return the data at that adress.

If @error Then
ConsoleWrite("! DllCall() failed. @error: " & @error & @CRLF)
ElseIf $aResult[0] Then
_GetErrorMessage($aResult[0])
Else
$hClientHandle = $aResult[4] ;hClientHandle is the fourth parameter.
ConsoleWrite("We now have have a client handle we can use in other functions!" & @CRLF)
EndIf

DllClose($hDLL)

Func _GetErrorMessage($iErrCode) ;Don't worry about this function for now. used to turn an error code into plain text
Local $tBuffer, $sErrMsg
$tBuffer = DllStructCreate("wchar Msg[128]")
DllCall("Kernel32.dll", "int", "FormatMessageW", "int", 0x1000, "hwnd", 0, "int", $iErrCode, "int", 0, "ptr", DllStructGetPtr($tBuffer), "int", DllStructGetSize($tBuffer) / 2, "ptr", 0)
$sErrMsg = DllStructGetData($tBuffer, "Msg")
ConsoleWrite("! " & $sErrMsg & @CRLF)
EndFunc

the WlanEnumInterfaces function is a bit more tricky, but have a go and see if you can get that GUID (or pointer to it...) I'll give you a hand if you get stuck.

Good Luck,

Matt

Edited by MattyD
Link to comment
Share on other sites

Got it right?

$DLL = DllOpen("wlanapi.dll")
$Call = DllCall($DLL, "dword", "WlanOpenHandle", "dword", 2, "ptr", 0, "dword*", 0, "hwnd*", 0)
ConsoleWrite("//---OpenHandle---" & @CRLF)
ConsoleWrite("Return value: " & $Call[0] & @CRLF)
ConsoleWrite("Return value: " & $Call[1] & @CRLF)
ConsoleWrite("Return value: " & $Call[2] & @CRLF)
ConsoleWrite("Return value: " & $Call[3] & @CRLF)
ConsoleWrite("Return value: " & $Call[4] & @CRLF)
$hClientHandle = $Call[4]
$a_iCall = DllCall($DLL, "dword", "WlanEnumInterfaces", "hwnd", $hClientHandle , "ptr", 0, "ptr*", 0)
Sleep(1000)
ConsoleWrite("//---EnumInterfaces---" & @CRLF)
ConsoleWrite("Return value: " & $a_iCall[0] & @CRLF)
ConsoleWrite("ClientHandle: " & $a_iCall[1] & @CRLF)
ConsoleWrite("Reserved: " & $a_iCall[2] & @CRLF)
ConsoleWrite("pInfo_List: " & $a_iCall[3] & @CRLF)
$pInfoList = $a_iCall[3]
$Call = DllCall($DLL, "dword", "WlanGetAvailableNetworkList", "hwnd", $hClientHandle, "ptr", $pInfoList, "dword", 0, "ptr", 0, "ptr*", 0)
ConsoleWrite("----------" & @CRLF)
ConsoleWrite("Return value1: " & $Call[0] & @CRLF)
ConsoleWrite("Return value2: " & $Call[1] & @CRLF)
ConsoleWrite("Return value3: " & $Call[2] & @CRLF)
ConsoleWrite("Return value4: " & $Call[3] & @CRLF)
ConsoleWrite("Return value5: " & $Call[4] & @CRLF)
ConsoleWrite("Return value6: " & $Call[5] & @CRLF)
DllClose($DLL)
Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

If you want to call WlanGetAvailableNetworkList,you must follow the logical order:

1. http://msdn.microsoft.com/en-us/library/windows/desktop/ms706716%28v=vs.85%29.aspx

2. http://msdn.microsoft.com/en-us/library/windows/desktop/ms706873%28v=vs.85%29.aspx

3. http://msdn.microsoft.com/en-us/library/windows/desktop/ms706868%28v=vs.85%29.aspx

And here we are, there is the InterfaceGUID you need to call the function.

Link to comment
Share on other sites

If you want to call WlanGetAvailableNetworkList,you must follow the logical order:

1. http://msdn.microsoft.com/en-us/library/windows/desktop/ms706716%28v=vs.85%29.aspx

2. http://msdn.microsoft.com/en-us/library/windows/desktop/ms706873%28v=vs.85%29.aspx

3. http://msdn.microsoft.com/en-us/library/windows/desktop/ms706868%28v=vs.85%29.aspx

And here we are, there is the InterfaceGUID you need to call the function.

Thanks for that reponse but it's my first time using DLL. Never used them before.

I understand the 1st link but not the second and the 3rd one. They are structures. How do i get their returns?

DllStructCreate? If yes would it be like that? Never used it before and i have 0 knowledge of dlls.

As i understood from a bit search on help files

$var = "wchar WLAN_INTERFACE_INFO_LIST;dword dwNumberOfItems;dword dwIndex;"
DllStructCreate($var)
Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

Alls OK, its a bit of a learning curve. I'll try to help without totally giving up the goods :)

A struct is basically a chunk of contiguous memory. in your snippet above, you have allocated 10 bytes of memory - a WCHAR is 2 bytes and a dword is 4 bytes. if you call DllStructGetPtr($var) you will know the location of your chunk of memory.

If you had pointed DllStructCreate to a particular place in memory, the function would not have actually allocated memory. Rather it would just define how the memory from that pointer should be broken up.

The WlanEnumInterfaces function allocates memory, fills it with data, then tells you where it is. the first two elements of a WLAN_INTERFACE_INFO_LIST structure are dwords, so your code should start to look a little like this:

$tInfoList = DllStructCreate("dword ItemCount; dword Index", $pInfoList); $pInfoList is a pointer to a WLAN_INTERFACE_INFO_LIST structure

Obviously it needs to be expanded on a bit.

Does this make any sense?

Matt

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...