Jump to content

DllCall() 'char' type ( & proper DllCall() usage )


Mechaflash
 Share

Recommended Posts

using DllCall() and ran into a function that defines a parameter as 'char'. I'm using 'str' right now in its place, and the DllCall() completes, but the function itself is giving errors.

Just want to make sure... is 'str' is the correct replacement for 'char' type?

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Try BYTE

Using 'BYTE', DllCall() also completes (but having same problems with the function). 'BYTE' and 'str' have some type of correlation?

I'm beginning to think the problem is with the DLL itself. I don't think the documentation on the return values are correct.

Using the 'Connexion' function, and it keeps returning 1... meaning the environment variable for ExtraPuTTY hasn't been set. Yet I've quadrouple checked, and it does exist (it gets created upon installation). I also added it to the local user's environment but it still returns the same value.

$sDll = "C:Program FilesExtraPuTTYBinExtraPuTTY.dll"
$i = DllCall($sDll, "int", "Connexion", "BYTE", "192.168.1.5", "ULONG", "1001", "BYTE", "root", "BYTE", "password", "BOOL", "TRUE", "long", "1", "ULONG", "22", "long", "0", "int", "1", "ULONG", "2^1")
msgbox(0,"",@error & @CRLF & $i[0])
$i = DllCall($sDll, "int", "CloseConnexion", "ULONG", "1001")
msgbox(0,"",@error & @CRLF & $i[0])
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

for example, for

;unsigned long *ConnectionId

$ConnectionId = 1001
$dllstruct = DllStructCreate("ulong")
DllStructSetData($dllstruct,1,$ConnectionId)
$ConnectionIdptr = DllStructGetPtr($dllstruct)
 
;"ulong*", $ConnectionIdptr
your second parameter

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

for example, for

;unsigned long *ConnectionId

$ConnectionId = 1001
$dllstruct = DllStructCreate("ulong")
DllStructSetData($dllstruct,1,$ConnectionId)
$ConnectionIdptr = DllStructGetPtr($dllstruct)

;"ulong*", $ConnectionIdptr
your second parameter

Ohhhhh... so any of the parameters that have '*' have to be built into a struct first because they are required to be a pointer?

Even if you say "yes" to the above, I still don't understand how structs/pointers work, but I'll figure it out in due time XD

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

As well as WinAPIEx too. Both UDFs will give you an idea of where to start.

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

Hmm... looking at WinAPIEx line 1651, there's this:

DllCall('advapi32.dll', 'int', 'LookupPrivilegeNameW', 'ptr', 0, 'ptr', DllStructGetPtr($tTP2, 2) + 12 * $i, 'ptr', DllStructGetPtr($tData), 'dword*', 128)

I notice dword has an * (to specify that it's a pointer?) but the value given is a direct integer.

for example, for

;unsigned long *ConnectionId

$ConnectionId = 1001
$dllstruct = DllStructCreate("ulong")
DllStructSetData($dllstruct,1,$ConnectionId)
$ConnectionIdptr = DllStructGetPtr($dllstruct)

;"ulong*", $ConnectionIdptr
your second parameter

What I get from the above quote is that I'm supposed to build the struct/pointer for it? However the example doesn't show this. Can someone explain what I'm missing from this?
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

$dllstruct = DllStructCreate("ulong") ; creates a ulong struct

DllStructSetData($dllstruct,1,$ConnectionId) ; sets value of the ulong

$ConnectionIdptr = DllStructGetPtr($dllstruct) ; retrieves the pointer , pointer to a ulong

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

using DllCall() and ran into a function that defines a parameter as 'char'. I'm using 'str' right now in its place, and the DllCall() completes, but the function itself is giving errors.

Just want to make sure... is 'str' is the correct replacement for 'char' type?

No it's not.

Your types are (respectively): str, ulong*, str, str, bool, long, ulong, long, int*, ulong.

Here:

$aArray = DllCall($sDll, "int", "Connexion", _
   "str", "192.168.1.5", _
   "ulong*", 1001, _
   "str", "root", _
   "str", "password", _
   "bool", 1, _
   "long", 1, _
   "ulong", 22, _
   "long", 0, _
   "int*", 1, _
   "ulong", 2)

JohnOne is overthinking.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

That does not surprise me.

Does Autoit automagically pass the pointer then, when you prepend * to type?

And does it just automagically pass the first element address of a string and null terminate it?

And would that mean you never have to prepend str type?

Sorry for the array of questions.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Sorry for the array of questions.

Local $aQs[4]
Local $aAs[3]
Local $sTitle = "JohnOne"

$aQs[0] = 3
$aQs[1] = "Does Autoit automagically pass the pointer then, when you prepend * to type?"
$aQs[2] = "And does it just automagically pass the first element address of a string and null terminate it?"
$aQs[3] = "And would that mean you never have to prepend str type?"

For $i = 1 To $aQs[0]
$aAs[$i -1] = msgbox(4 + 32, "JohnOne's Question", $aQs[$i])
If $aAs[$i - 1] = 6 Then
$sA = _YesAnswers()
Else
$sA = _NoAnswers()
EndIf
msgbox(48, "Trancexx's Answers", $sA)

Next

Func _YesAnswers()
Local $sY[3]
$sY[0] = "Yes"
$sY[1] = "Of course..."
$sY[2] = "You didn't know that?"
Return $sY[Random(0, 2, 1)]
EndFunc

Func _NoAnswers()
Local $sN[3]
$sN[0] = "No"
$sN[1] = "That's not what I said..."
$sN[2] = "Don't be silly."
Return $sN[Random(0, 2, 1)]
EndFunc

Now there's an array of questions with a msgbox answering system XD

Sorry. I come up with weird stuff all the time XD

Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

That does not surprise me.

Does Autoit automagically pass the pointer then, when you prepend * to type?

And does it just automagically pass the first element address of a string and null terminate it?

And would that mean you never have to prepend str type?

Sorry for the array of questions.

Since the questions are on the table (you will see what I mean here when new version of AutoIt is out), the answers are...

Yes, if you add asterisk AutoIt internally makes memory buffer in size of specified type and passes its pointer.

str is memory buffer filled with string; array of characters + null terminator, whose pointer is then passed. Address of the buffer is the address of the first character, obviously.

str* is also a valid type, but that's not the same as str. It's pointer to str pointer.

Edited by trancexx

♡♡♡

.

eMyvnE

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...