Jump to content

DLLCALL Help "DeletefFile API"


Recommended Posts

Hi mates, today I'm trying to learn how API work but I'm not able to make it work.

I'm new using WIndows API.

I trying with this but does not work.

DllCall("kernel32.dll","nonzero","DeleteFile","long int","C:\Users\usuario\Desktop\1.txt")

I know that there are many better ways to do this but I want to learn with API.

I can't find some tutorial about API for autoit using.

Sorry for my bad english.

Link to comment
Share on other sites

thank you very much work.

can you recommend me something to know what types like "str" should I choose?

because I thought that the types were these

char

short int(short)

int

long int (long)

bool

float

double

long double

wchar_t

or is there one for autoit?

Thank you

Edited by Danyfirex
Link to comment
Share on other sites

Hi Danyfirex,

if you look at the AutoIT help, you will see that the 2nd argument should be the return type of the API. If I remember correctly, the return type is an 8-bit boolean. So instead of "nonzero", you could have "BOOLEAN".

(from the help)

Valid Types are:

Type............Details

...

BOOLEAN....an unsigned 8 bit integer

Then the 4th parameter should be the argument type (LPCSTR in C), which for autoit should just be "str":

(from the help)

Conversions from Windows API types to AutoIt types:

WINDOWS API Type........AutoIt Type

LPCSTR/LPSTR...............str

Then you want to make sure that you are really using the dll. It may not be found, it may give errors, etc. So to do that, I would advise to do it in 2 steps: first, open the dll and get a handle, then use DLLCall with the handle.

step 1:

Dim $Dll = DllOpen ( "C:MyFolderMyDLL.dll" )

after that you can verify the $Dll value and make sure it's valid, with something like "msgbox(0,"",$Dll)

if it is not valid (returns a "-1") it probably did not find (typo in the path), or could not open the dll. If it is valid ($Dll > -1), do the call with something like

Dim $Response = DllCall ( $Dll, "BOOLEAN", "DeleteFile", "str", "C:MyOtherFolderMyFileToDelete")

Good luck ;)

oops, it looks like others posted while I was writing this...

Edited by rodent1
Link to comment
Share on other sites

thank you rodent1. I understand. So I going to read about Conversions from Windows API types to AutoIt types.

and need to impruve my english to understand that long english documentation. thank you mates.

Link to comment
Share on other sites

You can also look into WinAPI (and other) standard include files sources to see how DllCall for Windows API functions are used and compare it to original MSDN documentation for these API functions.

C:Program FilesAutoIt3IncludeWinAPI.au3

EDIT:also look here

Edited by Zedna
Link to comment
Share on other sites

Link to comment
Share on other sites

Link to comment
Share on other sites

I got some doubt about tutorial " Dealing_with_Dll" about "wstr","C:","dword*", I think, it should be str because

Conversions from Windows API types to AutoIt types :

LPCSTR/LPSTR = str

and MSDN says

BOOL WINAPI GetDiskFreeSpace(

__in LPCTSTR lpRootPathName,

__out LPDWORD lpSectorsPerCluster,

__out LPDWORD lpBytesPerSector,

__out LPDWORD lpNumberOfFreeClusters,

__out LPDWORD lpTotalNumberOfClusters

);

this code of tutorial.

; Variables to pass as reference Local
$SectorsPerCluster Local $BytesPerSector Local
$NumberOfFreeClusters Local
$TotalNumberOfClusters $calldata=DllCall("Kernel32.dll","int","GetDiskFreeSpaceW","wstr","C:","dword*",$SectorsPerCluster,"dword*",$BytesPerSector,"dword*",$NumberOfFreeClusters,"dword*",$TotalNumberOfClusters)
; The data is returned as an array, even the changed values of the variables
$SectorsPerCluster=$calldata[2]
$BytesPerSector=$calldata[3]
$NumberOfFreeClusters=$calldata[4]
$TotalNumberOfClusters=$calldata[5]
MsgBox(0,"","Total number of clusters: "&$TotalNumberOfClusters)
Edited by Danyfirex
Link to comment
Share on other sites

Yeah, that's something not so obvious. In the beginning the Windows API was pure ANSI, but in time the need for Unicode support grew overwhelming. The default documentation is in most cases still ANSI, but take a look at the bottom of the MSDN article where it says GetDiskFreeSpaceW (Unicode). Drive letters are obviously always Ansi, but afaik you also can check the freespace on sever hdds with this, and thoses paths might contain Unicode characters. So it's always better to call a Unicode version (is there any reason to call the Ansi version at all?) and replace the str parameter with wstr (of course always check if there is a Unicode version of the function available and if it might make sense to use unicode).

Edited by KaFu
Link to comment
Share on other sites

In the beginning the Windows API was pure ANSI, but in time the need for Unicode support grew overwhelming. The default documentation is in most cases still ANSI, but take a look at the bottom of the MSDN article where it says GetDiskFreeSpaceW (Unicode).

That is not always correct, please read the parameter type carefully:

LPSTR / LPCSTR / char* --> str, regardless of th function name

LPWSTR / LPCWSTR / wchar_t* --> wstr, regardless of function name

LPTSTR / LPCTSTR / TCHAR* --> str for ANSI calls (no suffix or ...A, e.g. LoadLibray, LoadLibraryA)

... but wstr for UNICODE calls (suffix ...W, e.g. LoadLibraryW)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

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