Jump to content

Recommended Posts

Posted

Hello,

I want to ask you how to handle the enum keyword in AutoIt, since I am not very familiar with enumerations in AutoIt.

So, I already checked the Help files description, for enums:  http://www.autoitscript.com/autoit3/files/beta/autoit3-docs/keywords/Enum.htm

But, I am currently playing arround with DllCall's and stuff, I have a enumeration like this:

Return code/valueDescription

FILE_TYPE_CHAR 0x0002

The specified file is a character file, typically an LPT device or a console.

FILE_TYPE_DISK 0x0001

The specified file is a disk file.

FILE_TYPE_PIPE 0x0003

The specified file is a socket, a named pipe, or an anonymous pipe.

FILE_TYPE_REMOTE 0x8000

Unused.

FILE_TYPE_UNKNOWN 0x0000

Either the type of the specified file is unknown, or the function failed.

 
In C# I would enumerate it like this:
 
  Quote

enum FileType : uint

    {
    FileTypeChar = 0x0002,
    FileTypeDisk = 0x0001,
    FileTypePipe = 0x0003,
    FileTypeRemote = 0x8000,
    FileTypeUnknown = 0x0000,
    }

 

But I am not sure how to do it with AutoIt.

How can I clear make a enumeration with all variables holding the differnent values?

Can someone point me to the right direction? :)

Posted (edited)

This would be in AutoIt:

Global Enum $FileTypeUnknown, $FileTypeDisk, $FileTypeChar, $FileTypePipe, FileTypeRemote = 0x8000
Edited by water

My UDFs and Tutorials:

  Reveal hidden contents

 

  • Moderators
Posted

MadaraUchiha,

What you have in that C# code looks like a datatype declaration and subsequent variable assignment - remember that in AutoIt you do not need to declare the datatype as we only have one. ;)

Enum essentially declares a list of variables with a fixed interval between them. So in your case you could do something like this:

; These will be set automatically to 0, 1, 2, 3
Local Enum $FILE_TYPE_UNKNOWN, $FILE_TYPE_DISK, $FILE_TYPE_CHAR, $FILE_TYPE_PIPE
; But you will have to declare this one separately
Local $FILE_TYPE_REMOTE = 0x8000
I question whether this is much of a saving over a full declaration:

Local $FILE_TYPE_UNKNOWN = 0, $FILE_TYPE_DISK = 1, $FILE_TYPE_CHAR = 2, $FILE_TYPE_PIPE = 3, $FILE_TYPE_REMOTE = 0x8000
Your choice. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

I was a bit faster ;), but Melba's given a more complete explanation.

If your enumeration starts with 0 and increments in steps of 1 you can use the defaults and shorten the code a bit (as you can see in my example).

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

First, thanks you two for your replies.

I already realized, I also can do it like this, can't I?

Global Enum $FileTypeChar = 0x0002, $FileTypeDisk = 0x0001, $FileTypePipe = 0x0003, $FileTypeRemote = 0x8000, $FileTypeUnknown = 0x0000

MsgBox(0,'','FileTypeChar : ' & $FileTypeChar)
MsgBox(0,'','FileTypeDisk : ' & $FileTypeDisk)
MsgBox(0,'','FileTypePipe : ' & $FileTypePipe)
MsgBox(0,'','FileTypeRemote : ' & $FileTypeRemote)
MsgBox(0,'','FileTypeUnknown : ' & $FileTypeUnknown)

But one thing is confusing me: Make these values constants.

I've I place the const keyword before the variable or before the enum keyword I get a syntax error? ;o

Global const Enum $FileTypeChar = 0x0002, $FileTypeDisk = 0x0001, $FileTypePipe = 0x0003, $FileTypeRemote = 0x8000, $FileTypeUnknown = 0x0000

MsgBox(0,'','FileTypeChar : ' & $FileTypeChar)
MsgBox(0,'','FileTypeDisk : ' & $FileTypeDisk)
MsgBox(0,'','FileTypePipe : ' & $FileTypePipe)
MsgBox(0,'','FileTypeRemote : ' & $FileTypeRemote)
MsgBox(0,'','FileTypeUnknown : ' & $FileTypeUnknown)

:ermm:

Posted

Can't test it at the moment, but I think keyword Enum makes them a Constant by default.

Try to assign a new value to one of the variables.

My UDFs and Tutorials:

  Reveal hidden contents

 

  • Moderators
Posted

water,

  Quote

keyword Enum makes them a Constant by default

Correct. :thumbsup:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

That was easy - it wouldn't be sensible the other way round ;)

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Hm, is it possible to name my enumeration somehow? Because the return type of my DllCall to kernel32.DLL GetFileType has one of those as return type...

And I need to set them as return type somehow;o

Posted

As you can see from the syntax description in the help file you can't assign a name to the enumeration.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Declare a variable. Based on your  C# code it would be named $Filetype.

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

Yes, but I already declared it in my enum? ;o

And since the return tyoe can be different in different cases, I need to make it decide whats the correct one...

Global Enum $FileTypeChar = 0x0002, $FileTypeDisk = 0x0001, $FileTypePipe = 0x0003, $FileTypeRemote = 0x8000, $FileTypeUnknown = 0x0000


Local $result = DllCall("kernel32.dll", "???", "GetFileType", Parameter stuff??)

But How? I am not so experienced with this stuff yet :/

Posted

If you check the help file for DllCall you will see that you have to define the type of the returned result. The help file lists tghe valid types (Int, str etc.).

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

MU,

The Windows function "GetFileType" only returns one type of value.  See this doc.

Also, your reply in post #5 leads me to believe that you do not understand M23's reply in post #3.

Enum does nothing more than assign incrementing values to constants.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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
  • Recently Browsing   0 members

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