Sign in to follow this  
Followers 0
senthor

Translating AHK to AU3

5 posts in this topic

Hi!

I'm currently trying to create a tool to control iTunes with the windows media keyboard functions.

I found a pretty good source, but it's written in Autohotkey.

And this is the first thing I just can#t get translated...

CoDecodeInteger(ptr)
{
   Return *ptr | *++ptr << 8 | *++ptr << 16 | *++ptr << 24
}

I got it like this:

Func CoDecodeInteger($ptr)
   Return *$ptr OR *++$ptr << 8 OR *++$ptr << 16 OR *++$ptr << 24
EndFunc

I jsut don't get these "*", "*++" and "<<" operators!

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

* dereferences a pointer (gets you an alias for the data pointed to by the pointer)

++ pre-increments the pointer (it's basically like an inline $ptr += (something), where (something) is the size of the item pointed to by the pointer)

<< is a bitwise left-shift on the dereferenced value in this case (can be performed using BitShift($ptr, -(number to right of <<)))

| is a bitwise or (meaning you'd need to use BitOR(), not just a logical OR)

Since there are no native pointers for AutoIt variants, I'm not sure there is any direct way to translate the code (specifically, the pointer incrementing and dereferencing).

You might be able to play with an AutoIt array (or depending on the data type, the DllStruct*() functions) to achieve the desired effect, but that will most likely require changes in other parts of the code outside of this function.

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The hole code partly translated is:

func iTunes($command)
    $muc_piT := ObjCreate( "{DC0C2640-1415-4644-875C-6F4D769839BA}", "{9DD6680B-3EDC-40DB-A771-E6FE4832E34A}" )
    DllCall( VTable( $muc_piT, $command ), "Uint", $muc_piT )
    $muc_piT = 0
EndFunc


Func VTable($ppv, $idx)
   Return CoDecodeInteger(CoDecodeInteger($ppv) + $idx * 4)
EndFunc

Func CoDecodeInteger($ptr)
   Return *$ptr | *++$ptr << 8 | *++$ptr << 16 | *++$ptr << 24
EndFunc

But I don't get the $muc_piT := ObjCreate, and you have to help me a little...

$command is a number between 0 and 19.

Edited by senthor

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I can't say I'm familiar with handling COM objects in AutoIt, but from looking at the docs for ObjCreate(), it seems to me that you're using it incorrectly. The second parameter is supposed to be the name of the remote computer, not a CLSID. As well, the first parameter is supposed to be a class name -- I'm not sure if AutoIt accepts CLSIDs for that either.

The DllCall doesn't look right either. Unless you already have a handle opened for some DLL, the first parameter is supposed to be a filename, not an integer.

Is there any reason the iTunes UDF wouldn't suffice?

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Share this post


Link to post
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
Sign in to follow this  
Followers 0