Administrators Jon Posted December 28, 2004 Administrators Share Posted December 28, 2004 (edited) DllCall is great. But it can be tricky to use. Here are some syntax notes geared towards using the Windows API. When you manage to get DllCall to work with a new api then please post the syntax you used and the MSDN API syntax so that others may benefit. I'll merge all the posts into this one.Windows APIAll the Windows API details you need can be found by searching at MSDN LibraryCommon DatatypesAutoIt has a single datatype - the variant. A variant can hold HWNDs (window handles), integers (32 and 64bit), floating point numbers (doubles). Windows API calls take many different sorts of datatypes and in the DllCall function you must work out which type to use for conversion. Complete list of Windows DatatypesWindows Datatype = DllCall TypeBOOL = "int"COLORREF = "int"DWORD = "int"HANDLE = "ptr"HDC = "ptr"HFILE = "int"HFONT = "ptr"HICON = "ptr"HINSTANCE = "ptr"HKEY = "ptr"HMENU = "ptr"HMODILE = "ptr"HWND = "hwnd"INT = "int"LONG = "long"LPARAM = "long"LPCTSTR = "str" ("wstr" if a UNICODE function)LPINT = "int_ptr"LPLONG = "long_ptr"UINT = "int"ULONG = "long"WPARAM = "int"API ListHere is a list of API functions that have been used successfully in AutoIt and their respective DllCall syntax.GetAsyncKeyState - DllCall("user32.dll", "int", "GetAsyncKeyState", "int", $hexKey)GetTickCount - DllCall("kernel32.dll", "long", "GetTickCount")MessageBeep - DllCall ("user32.dll", "int", "MessageBeep", "int", 0xFFFFFFFF)MessageBox - DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "text", "str", "title", "int", 0)PrintUI /? - DllCall("printui.dll", "none", "PrintUIEntryW", "hwnd", 0, "ptr", 0, "wstr", "/?", "int", @SW_SHOWNORMAL) Edited December 30, 2004 by Jon Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
jpm Posted December 28, 2004 Share Posted December 28, 2004 (edited) I would have prefer a syntax like DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "text", "str", "title", "int", 0) DllCall("printui.dll", "none", "PrintUIEntryW", "hwnd", 0, "ptr", 0, "wstr", "/?", "int", @SW_SHOWNORMAL) being DllCall("user32.dll", "int = MessageBox(hwnd,str,str,int)", 0, "text", "title", 0) DllCall("printui.dll", "PrintUIEntryW(hwnd,ptr,wstr,int)", 0, 0, "/?", @SW_SHOWNORMAL) Edited December 28, 2004 by jpm Link to comment Share on other sites More sharing options...
ezzetabi Posted December 28, 2004 Share Posted December 28, 2004 Changing Wallpapers, only with Active Desktop disabled and with .bmp files.For using other filetypes check topng.exe from bcheck site for converting on-the fly.expandcollapse popupFunc _ChangeWallpaper($sFile,$iType) ; Changes the wallpaper to $sFilename using $iType as: ; 1 Tiled ; 2 Centered ; 3 Stretched ; any other value (usually 0) unchanged ; Returns ; 0 if everything is allright. ; -1 if $sFile does not exist. @error is set to 1 ; -2 if $sFile is not a .bmp file. @error is set to 2 If Not FileExists($sFile) Then SetError(1) Return -1 EndIf If StringTrimLeft($sFile,StringInStr($sFile,'.',0,-1)) <> 'bmp' Then SetError(2) Return -2 EndIf Select Case $iType = 1 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','1') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 2 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 3 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','2') Case Else ; EndSelect RegWrite('HKCU\Control Panel\Desktop','Wallpaper','reg_sz',$sFile) DllCall("user32","int","SystemParametersInfo","int",20,"int",0,"str",$sFile,"int",0) Return 0 EndFuncInstalling new fonts:Func _InstallFont($sFileName) If FileMove($sFileName, @WindowsDir & '\Fonts', 1) Then $sFileName = @WindowsDir & '\Fonts\' & StringTrimLeft($sFileName, StringInStr($sFileName, '\', 0, -1)) DllCall('gdi32', 'long', "AddFontResourceA", 'String', $sFileName) Return 1 Else Return 0 EndIf EndFunc ;==>_InstallFontUninstalling fonts...Func _UnInstallFonts($sFontsName) Local $sFileName = @WindowsDir & '\fonts\' & $sFontsName $a = DllCall('gdi32', 'long', "RemoveFontResourceA", 'String', $sFileName) If Not @error And $a[0] <> 0 Then FileDelete($sFileName) Return 1 Else Return 0 EndIf EndFunc ;==>_UnInstallFontsReturns the number of ms that have elapsed since, Windows has started$r = DllCall('kernel32','long','GetTickCount') MsgBox(4096,'Time','Windows started ' & $r[0] & ' ms ago.')ShellExecute one of the most useful!Func _ShellExecuteDllCall($sCmd, $sVerb, $sArg, $sFolder) Local $aRet $aRet = DllCall("shell32.dll", "long", "ShellExecute", "hwnd", 0, "string", $sVerb, _ "string", $sCmd, "string", $sArg, "string", $sFolder, "long", @SW_SHOWNORMAL) Return $aRet If $aRet[0] > 32 Then Return 1;All Ok Else Return 0;Problems EndIf EndFunc ;==>_ShellExecuteDllCall Link to comment Share on other sites More sharing options...
Administrators Jon Posted December 28, 2004 Author Administrators Share Posted December 28, 2004 I would have prefer a syntax like DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "text", "str", "title", "int", 0) DllCall("printui.dll", "none", "PrintUIEntryW", "hwnd", 0, "ptr", 0, "wstr", "/?", "int", @SW_SHOWNORMAL)beingDllCall("user32.dll", "int = MessageBox(hwnd,str,str,int)", 0, "text", "title", 0) DllCall("printui.dll", "PrintUIEntryW(hwnd,ptr,wstr,int)", 0, 0, "/?", @SW_SHOWNORMAL)Bit late for that don't you think?! Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
layer Posted December 28, 2004 Share Posted December 28, 2004 one of Ezzetabi's functions... Func _IsPressed($hexKey) Local $aR, $bRv $hexKey = '0x' & $hexKey $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey) If $aR[0] <> 0 Then $bRv = 1 Else $bRv = 0 EndIf Return $bRv EndFunc Checks if any keys were pressed. FootbaG Link to comment Share on other sites More sharing options...
Nova Posted December 29, 2004 Share Posted December 29, 2004 So how would I use dllcall with this ?long auxSetVolume(UINT uDeviceID,DWORD dwVolume);Ive tryed a few varations but nothing works, and theres no reference telling me wether its user32.dll or printui.dll or whatever.dllFound from Source 1 or Source 2Plz help Link to comment Share on other sites More sharing options...
layer Posted December 29, 2004 Share Posted December 29, 2004 about the soruces to see what dll it is... id assume "winmm.dll" because most of the DLL's ive seen have had the same name as the librarys... FootbaG Link to comment Share on other sites More sharing options...
jpm Posted December 29, 2004 Share Posted December 29, 2004 Bit late for that don't you think?! <{POST_SNAPBACK}>for me NO, but for Larry ... :"> perhaps we can put an Opt("DllCallFormatMode",1) Link to comment Share on other sites More sharing options...
Administrators Jon Posted December 29, 2004 Author Administrators Share Posted December 29, 2004 about the soruces to see what dll it is... id assume "winmm.dll" because most of the DLL's ive seen have had the same name as the librarys...That's listed in MSDN too. Here the the MSDN page for MessageBox - notice down at the bottom it tells you what dll to use.http://msdn.microsoft.com/library/en-us/wi.../messagebox.asp Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Nova Posted December 29, 2004 Share Posted December 29, 2004 Why can we just use the dlls as they are ? Why must their form be changed for autoit ?If this is to somehow make it easier to call dlls, then im very confussed. perhaps we can put an Opt("DllCallFormatMode",1)Are you suggesting that after setting such an opt to 1, that you could use the dll straight as their shown on the msdn library, without editing ? Link to comment Share on other sites More sharing options...
this-is-me Posted December 29, 2004 Share Posted December 29, 2004 What he is saying is that the syntax of DllCall("user32.dll", "int = MessageBox(hwnd,str,str,int)", 0, "text", "title", 0) is easier to type and read than DllCall("user32.dll", "int", "MessageBox", "hwnd", 0, "str", "text", "str", "title", "int", 0) Who else would I be? Link to comment Share on other sites More sharing options...
layer Posted December 29, 2004 Share Posted December 29, 2004 i know this is simple but if you want to add a beep to your script, use this: DllCall ("user32.dll", "int", "MessageBeep", "int", 0xFFFFFFFF) FootbaG Link to comment Share on other sites More sharing options...
Administrators Jon Posted December 30, 2004 Author Administrators Share Posted December 30, 2004 i know this is simple but if you want to add a beep to your script, use this:DllCall ("user32.dll", "int", "MessageBeep", "int", 0xFFFFFFFF)This should probaby be added as a builtin function too I think. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
Josbe Posted December 30, 2004 Share Posted December 30, 2004 This should probaby be added as a builtin function too I think.<{POST_SNAPBACK}>Oh, very well. Perhaps, would be fine a traditional beep like a builtin function. Beep( Frequency, Duration)DLL's sample:DllCall ("kernel32.dll", "long", "Beep", "long", 450, "long", 100) DllCall ("kernel32.dll", "long", "Beep", "long", 360, "long", 100) AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
layer Posted December 30, 2004 Share Posted December 30, 2004 Oh, very well. Perhaps, would be fine a traditional beep like a builtin function. Beep( Frequency, Duration)DLL's sample:DllCall ("kernel32.dll", "long", "Beep", "long", 450, "long", 100) DllCall ("kernel32.dll", "long", "Beep", "long", 360, "long", 100)<{POST_SNAPBACK}>good idea but i doubt that that would work on most peoples computer... as windows xp computers get more popular... u need to have N.T. 4.0 i think or later in order to run your above code... but maybe im wrong, maybe a lot of people do have N.T... because i had tried that dllcall but it's not compatible with my computer FootbaG Link to comment Share on other sites More sharing options...
Administrators Jon Posted December 30, 2004 Author Administrators Share Posted December 30, 2004 good idea but i doubt that that would work on most peoples computer... as windows xp computers get more popular... u need to have N.T. 4.0 i think or later in order to run your above code... but maybe im wrong, maybe a lot of people do have N.T... because i had tried that dllcall but it's not compatible with my computer Should work on anything:RequirementsClient: Requires Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95. Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
MHz Posted December 30, 2004 Share Posted December 30, 2004 Beep should use the internal PC speaker. Works here on XP Pro. Addition to Layers DllCall. Maybe usefull? DllCall ("user32.dll", "int", "MessageBeep", "int", 0x33333333);Exclamation DllCall ("user32.dll", "int", "MessageBeep", "int", 0x44444444);Error DllCall ("user32.dll", "int", "MessageBeep", "int", 0xFFFFFFFF);Layers Beep Link to comment Share on other sites More sharing options...
ezzetabi Posted December 30, 2004 Share Posted December 30, 2004 It is not better posting in Func form? Func _Beep($Frequency, $Duration) DllCall ("kernel32.dll", "long", "Beep", "long", $Frequency, "long", $Duration) EndFunc So even the noobest can understand. Link to comment Share on other sites More sharing options...
Josbe Posted December 30, 2004 Share Posted December 30, 2004 It is not better posting in Func form?Func _Beep($Frequency, $Duration) DllCall ("kernel32.dll", "long", "Beep", "long", $Frequency, "long", $Duration) EndFuncSo even the noobest can understand.<{POST_SNAPBACK}>Maybe. BTW: The "duration" parameter is a mess not to specify it. AUTOIT > AutoIt docs / Beta folder - AutoIt latest beta Link to comment Share on other sites More sharing options...
layer Posted December 30, 2004 Share Posted December 30, 2004 Should work on anything:<{POST_SNAPBACK}>hmmm.. funny, i forgot what site i was at and it said it only works on N.T. 4.0 or higher... maybe i read wrong :"> let me see if i can find the site... err can't find it.. damn it, i read wrong :"> sorry for the inconvinience! FootbaG Link to comment Share on other sites More sharing options...
Recommended Posts