Jump to content



Photo

DLLCALL Help "DeletefFile API"


  • Please log in to reply
14 replies to this topic

#1 Danyfirex

Danyfirex

    Polymath

  • Active Members
  • PipPipPipPip
  • 238 posts

Posted 13 April 2012 - 05:36 PM

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.

Posted Image






#2 JohnOne

JohnOne

    John

  • Active Members
  • PipPipPipPipPipPip
  • 8,824 posts

Posted 13 April 2012 - 05:44 PM

DllCall("kernel32.dll","int","DeleteFile","str","C:UsersusuarioDesktop1.txt")

Maybe

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363915(v=vs.85).aspx
AutoIt Absolute Beginners Require a serial
Run('hh mk:@MSITStore:'&StringReplace(@AutoItExe,'.exe','.chm')&'::/html/tutorials/helloworld/helloworld.htm','',@SW_MAXIMIZE)

#3 Danyfirex

Danyfirex

    Polymath

  • Active Members
  • PipPipPipPip
  • 238 posts

Posted 13 April 2012 - 05:54 PM

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, 13 April 2012 - 05:57 PM.

Posted Image


#4 rodent1

rodent1

    Wayfarer

  • Active Members
  • Pip
  • 63 posts

Posted 13 April 2012 - 05:59 PM

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, 13 April 2012 - 06:04 PM.


#5 Danyfirex

Danyfirex

    Polymath

  • Active Members
  • PipPipPipPip
  • 238 posts

Posted 13 April 2012 - 06:09 PM

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.

Posted Image


#6 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 13 April 2012 - 08:28 PM

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
http://www.autoitscript.com/forum/topic/56168-structs-and-dllcall-under-x64/

Edited by Zedna, 13 April 2012 - 08:30 PM.


#7 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,162 posts

Posted 13 April 2012 - 11:52 PM

Tutorial on DllCall() & DllStructs
Windows Data Types

#8 Danyfirex

Danyfirex

    Polymath

  • Active Members
  • PipPipPipPip
  • 238 posts

Posted 14 April 2012 - 02:33 PM

Thank you Zenda and KaFu. that helps me so much. ;)

Posted Image


#9 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,315 posts

Posted 14 April 2012 - 03:23 PM

Thank you Zenda and KaFu. that helps me so much. ;)


Zedna :)

#10 Danyfirex

Danyfirex

    Polymath

  • Active Members
  • PipPipPipPip
  • 238 posts

Posted 14 April 2012 - 04:50 PM

Zedna ;)

sorry Zedna.

Edited by Danyfirex, 14 April 2012 - 04:51 PM.

Posted Image


#11 Danyfirex

Danyfirex

    Polymath

  • Active Members
  • PipPipPipPip
  • 238 posts

Posted 14 April 2012 - 04:57 PM

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, 14 April 2012 - 05:00 PM.

Posted Image


#12 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,162 posts

Posted 14 April 2012 - 06:36 PM

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, 14 April 2012 - 06:37 PM.


#13 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 14 April 2012 - 07:32 PM

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* Posted Image [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

#14 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,162 posts

Posted 14 April 2012 - 07:59 PM

Did not know that, thanks for the clarification ;)!

#15 Danyfirex

Danyfirex

    Polymath

  • Active Members
  • PipPipPipPip
  • 238 posts

Posted 14 April 2012 - 09:33 PM

ok ;) now I understand, thank you for helping me :)

thank mates.

Posted Image





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users