Jump to content

DllCall


Jon
 Share

Recommended Posts

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! :idiot:

<{POST_SNAPBACK}>

If its not working on your pc maby your have your internal speaker disabled in add/remove hardware.
Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Ntfs encryption.

Func _NTFSEncrypt($sFilename)
   If FileExists($sFilename) and not StringInStr(FileGetAttrib($sFilename),'c') Then
      Local $aRet
      $aRet = DllCall('ADVAPI32','short',"EncryptFileA",'String',$sFilename)
      If $aRet[0] <> 0 Then 
         Return 1;All ok
      Else
         SetError(1)
         Return 0;Problems
      EndIf
   Else
      SetError(2)
      Return 0
   EndIf
EndFunc
   
Func _NTFSDecrypt($sFilename)
   If FileExists($sFilename) and StringInStr(FileGetAttrib($sFilename),'c') Then
      Local $aRet
      $aRet = DllCall('ADVAPI32','short',"DecryptFileA",'String',$sFilename,'long',0)
      If $aRet[0] <> 0 Then 
         Return 1;All ok
      Else
         SetError(1)
         Return 0;Problems
      EndIf
   Else
      SetError(2)
      Return 0
   EndIf
EndFunc
Edited by ezzetabi
Link to comment
Share on other sites

Create hard link

Func _CreateHardLink($sOrigFilename, $sDestFilename)
   If FileExists($sOrigFilename) Then
      Local $aRet
      $aRet = DllCall('kernel32.dll', 'long', 'CreateHardLinkA', 'String', $sDestFilename, "String", $sOrigFilename, 'int', 0)
      If Not @error And $aRet[0] <> 0 Then
         Return 1;All ok
      Else
         SetError(1)
         Return 0;Something goes wrong.
      EndIf
   Else
      SetError(2)
      Return 0;Original files does not exist.
   EndIf
EndFunc  ;==>_CreateHardLink
Link to comment
Share on other sites

E,

These should go in the scripts and scraps section. This post is just so people can get an idea of how to convert an MSDN style thing into an AutoIt thing. So it's just the actual dllcall line (for the parameter types) that I need. We'll never get a complete list as it's endless :idiot:

Link to comment
Share on other sites

E,

These should go in the scripts and scraps section.  This post is just so people can get an idea of how to convert an MSDN style thing into an AutoIt thing.  So it's just the actual dllcall line (for the parameter types) that I need.  We'll never get a complete list as it's endless :D

<{POST_SNAPBACK}>

That's a long time we didn't see you Jon :idiot:
Link to comment
Share on other sites

I am not sure what you mean Jon (test)... The msdn files are quite clear. The main problem are the type of variable that Autoit can't support like structs.

What should we post here?

Something like:

{

Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

}

means

DllCall ("kernel32.dll", "long", "Beep", "long", $dwFreq, "long", $dwDuration)

?

Thats is nothing more that changing order of the info...

(Jon... Congrats. The Autoit order is much clearer than the VB one... )

Link to comment
Share on other sites

  • 1 month later...

i was creating a SetPixel func and then i looked in the forum and gosu had already made one but ima post it anyways cause its part of my Pixel Func's so this is only one... :lmao:

Func SetPixel ($handle, $x, $y, $color)
    $dc= DllCall ("user32.dll", "int", "GetDC", "hwnd", $handle)
     DllCall ("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x, "long", $y, "long", $color)
     DllCall ("user32.dll", "int", "ReleaseDC", "hwnd", 0,  "int", $dc[0])
EndFunc

EDIT: like that?

Edited by layer
FootbaG
Link to comment
Share on other sites

Layer you should look at how you're using that function.

You point DllCall to variables and never use them... get rid of the variables and it'll look a lot cleaner.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

i took away the $realesedc and the $setpixel... is that what you meant? but i just thought that those could be later used in some certain script that would need it, i guess not, but thats what you meant right? :lmao:

FootbaG
Link to comment
Share on other sites

  • 3 weeks later...

want to make a console window? :lmao:

DllCall ("kernel32.dll", "int", "AllocConsole")
DllCall ("kernel32.dll", "int", "AttachConsole", "int", "AutoIt3.exe")
While 1
      Sleep (1000)
WEnd
Func OnAutoItExit()
      DllCall("kernel32.dll", "int", "FreeConsole")
EndFunc

(idea from Valik o:))

EDIT: Added the OnAutoItExit function to free the console when done... And I may be making a console library for future use... It won't actually be useful (well, maybe) but rather for the console finatic fans like me :) I just love the way they look.

EDIT2: Thanks this-is-me :)

Edited by layer
FootbaG
Link to comment
Share on other sites

  • 5 months later...

i dont know how you guys find these.I have a few docs and stuff but cant seem

to figure out how what goes where.Anyway heres the only one i got to work.

DllCall("shell32","long","ShellAboutA")

Edited by therion
Link to comment
Share on other sites

  • 2 weeks later...

BroadCastSystemMessage

;Type BSF_'s
Const $BSF_QUERY = 1
Const $BSF_IGNORECURRENTTASK = 2
Const $BSF_FLUSHDISK = 4
Const $BSF_NOHANG = 8
Const $BSF_POSTMESSAGE = 16
Const $BSF_FORCEIFHUNG 32
Const $BSF_NOTIMEOUTIFNOTHUNG = 64
;End BSF_'s

;Type BSM_'s
Const $BSM_ALLCOMPONENTS = 0 
Const $BSM_VXDS = 1 
Const $BSM_NETDRIVER = 2 
Const $BSM_INSTALLABLEDRIVERS = 4 
Const $BSM_APPLICATIONS = 8 
Const $BSM_ALLDESKTOPS  = 16
;end BSM_'s


Const $SC_MINIMIZE = 61472
Const $WM_SYSCOMMAND = 274
;long BroadcastSystemMessage( DWORD dwFlags,
  ;LPDWORD lpdwRecipients,
  ;UINT uiMessage,
  ;WPARAM wParam,
  ;LPARAM lParam);

Func BroadcastSystemMessage($dwFlags, $lpdwRec, $uiMsg, $wParam, $lParam)
$Call = DllCall("user32", "long", "BroadcastSystemMessage", "int", $dwFlags, "int_ptr", $lpdwRec, "Int", $uiMsg, "Int", $wParam, "long", $lParam )
Return $Call 
EndFunc

<Test.au3>

#include <BCSM.au3>

$Ret = BroadcastSystemMessage( $BSF_POSTMESSAGE, $BSM_APPLICATIONS, $WM_SYSCOMMAND, $SC_MINIMIZE, 0)

MsgBox(0, "Ret Value", $Ret)

</Test.au3>

Run Time Use of API

Dim $Krnl32 = ("Kernal32.Dll")
Dim $User32 = ("USER32.Dll")


Func LibFree($hLibModule)
$hKrnl = DllOpen($Krnl32)
DllCall($hKrnl, "long", "FreeLibrary", "long", hLibModule) 
$ClnKrnl = DllClose($hKrnl)
EndFunc;==>End func LibFree

Func LibLoad( $lpLibFileName )
$hKrnl = DllOpen($Krnl32)
$LibHandle = DllCall($hKrnl, "long", "LoadLibraryA", "str", $lpLibFileName)
$ClnKrnl = DllClose($hKrnl)
Return $LibHandle
EndFunc;==>End Func LibLoad

Func GetProcAddress( $hModule, $lpProcName)
$hKrnl = DllOpen($Krnl32)
$ProcessAddy = DllCall($hKrnl, "long", "GetProcAddress", "long", $hModule, "str", $lpProcName)
$ClnKrnl = DllClose($hKrnl)
Return $ProcessAddy
EndFunc;==>End Func GetProcAddress

Func CallWindowProc($lpPrevWndFunc, $hWnd, $Msg, $wParam, $iParam)
$hUser = DllOpen($User32)
DllCall($hUser, "long", "CallWindowProcA", "long", $lpPrecWndFunc, _
"hwnd", $hWnd, "str", $Msg, "int", $wParam, "long", $iParam)
$ClnUser = DllClose($hUser)
EndFunc;==>EndFunc CallWindowProc

Test File Coming Soon...

Edited by WSCPorts
http://www.myclanhosting.com/defiasVisit Join and contribute to a soon to be leader in Custumized tools development in [C# .Net 1.1 ~ 2.0/C/C++/MFC/AutoIt3/Masm32]
Link to comment
Share on other sites

  • 1 month later...

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.

<span style='font-size:13pt;line-height:100%'>Windows API</span>

All the Windows API details you need can be found by searching at MSDN Library

<span style='font-size:13pt;line-height:100%'>Common Datatypes</span>

AutoIt 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 Datatypes

Windows Datatype = DllCall Type

BOOL = "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"

<span style='font-size:13pt;line-height:100%'>API List</span>

Here 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)

Could you please add this to the help file?

This is really useful information.

Link to comment
Share on other sites

  • 2 weeks later...

This should probaby be added as a builtin function too I think.

Already done :P

Could you please add this to the help file?

This is really useful information.

Maybe some of it should be added... Because there is no sense having the info in two places ;) But then, you have people who don't come to the forums, or have no internet. But there are always little tips and tricks not in somethings documentation that are on the website.

Perhaps the Windows Datatype's could be added. Those look the most useful for the help file about now.

Edited by layer
FootbaG
Link to comment
Share on other sites

...And if they have no internet, then how did they download autoit?

I was gonna write how they had AutoIt, but I didn't think anybody would ask this, but at the same time I knew someone would :">

A few possibilities...

  • Their internet is down. (Temporarily, so it wouldn't be so bad)
  • They downloaded it on another computer, put it on a flash drive or some other storage device, and put it on their computer.
  • They're stupid and forgot how to get to the internet again ;)
  • None of the above, something else.
Ok, I know I know. Those are a little vague, and don't happen a lot. But I was just making a point.
FootbaG
Link to comment
Share on other sites

  • 6 months later...

global atom stuff...

Func _GlobalAddAtom($lpString, $hDll_Kernel32 = "kernel32.dll")
    Local $avRval = DllCall($hDll_Kernel32, "short", "GlobalAddAtom", "str", StringLeft($lpString, 255))
    If @error > 0 Then
        SetError(1); DllCall Error
        Return 0
    ElseIf $avRval[0] = 0 Then
        SetError(2); GlobalAddAtom Error
    EndIf
    Return $avRval[0]
EndFunc  ;==>_GlobalAddAtom

Func _GlobalDeleteAtom($iAtom, $hDll_Kernel32 = "kernel32.dll")
    Local $avRval = DllCall($hDll_Kernel32, "short", "GlobalDeleteAtom", "short", $iAtom)
    If @error > 0 Then
        SetError(1); DllCall Error
        Return 0
    EndIf
    Return $avRval[0]
EndFunc  ;==>_GlobalDeleteAtom

Func _GlobalGetAtomName($iAtom, $iBuffSize = 256, $hDll_Kernel32 = "kernel32.dll")
    Local $vBuff = DllStructCreate("char[" & $iBuffSize & "]"), $sBuff
    Local $avRval = DllCall($hDll_Kernel32, "int", "GlobalGetAtomName", "short", $iAtom, "long", DllStructGetPtr($vBuff, 1), "int", $iBuffSize)
    If @error > 0 Then
        SetError(1); DllCall Error
        Return 0
    ElseIf $avRval[0] = 0 Then
        SetError(2); GlobalGetAtomName Error
        Return $avRval[0]
    EndIf
    $sBuff = DllStructGetData($vBuff, 1)
    $vBuff = 0
    Return $sBuff
EndFunc  ;==>_GlobalGetAtomName

Func _GlobalFindAtom($lpString, $hDll_Kernel32 = "kernel32.dll")
    Local $avRval = DllCall($hDll_Kernel32, "short", "GlobalFindAtom", "str", $lpString)
    If @error > 0 Then
        SetError(1); DllCall Error
        Return 0
    ElseIf $avRval[0] = 0 Then
        SetError(2); GlobalAddAtom Error
    EndIf
    Return $avRval[0]
EndFunc  ;==>_GlobalFindAtom

CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
Link to comment
Share on other sites

  • 2 weeks later...
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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