AutoHotkey Community

It is currently May 27th, 2012, 12:37 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: May 18th, 2010, 9:04 pm 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
A struct is a set of values in the memory, where the order and lenght of each member is defined.

For example a the Struct Point:
Code:
struct Point
{
 int X;
 int Y;
}

We have 2 int - that makes a 2 * 4 Bytes Memory block. (an int consumes 4 Bytes, in hex view 00 00 00 00)
X := 0xFF
Y := 0xFF
This will look like..
Code:
000000FF000000FF

...in the memory. (each byte consuming 2 digits in hex view)

To place these nums in the struct:
Code:
VarSetCapacity(Point, 8, 0) ; ->>                Point[0000000000000000]
NumPut(0xFF,Point,0,"UInt") ; ->> [000000FF] --> Point[000000FF00000000]
NumPut(0xFF,Point,4,"UInt") ; ->> [000000FF] --> Point[000000FF000000FF]

The comments tell what happens in the memory.

Hope this helps

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2010, 10:12 pm 
Offline

Joined: February 13th, 2010, 3:52 pm
Posts: 175
Very helpful, confirms pretty much what I thought. Thanks IsNull.

For strings, its the address of the string right? Could I do something like this to add the address of the string at the offset 4:
Code:
NumPut(&String,Point,4,"UInt")


Would that work? Or would I have to change the type or anything like that?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2010, 10:24 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
IsNull dont forget, if (asc = you) then break right :mrgreen:??

SifJar wrote:
Instead of writing say
Code:
NumPut( x1, &R+0 )
could you also use
Code:
NumPut( x1, &R, 0 )

:?: This seems to be what svi did in his code, when adding members to "mii" (MenuItemInfo), are they pretty much the same thing, or is there an important difference?
You are correct.
I asked the same question not too long ago ;).

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 18th, 2010, 10:35 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
SifJar wrote:
Code:
NumPut(&String,Point,4,"UInt")


Would that work? Or would I have to change the type or anything like that?
AHK will see the string as an unsigned integer, so yes it should be ok. The thing that you have to make sure of is that the pointer contains the valid data.

Be thankful its not c++ where the type also has to be converted :evil:..

You should definatly take a look at this:

http://www.autohotkey.com/forum/post-91578.html#91578

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2010, 11:58 am 
Offline
User avatar

Joined: May 10th, 2007, 10:54 am
Posts: 649
Location: .switzerland
SifJar wrote:
Very helpful, confirms pretty much what I thought. Thanks IsNull.

For strings, its the address of the string right? Could I do something like this to add the address of the string at the offset 4:
Code:
NumPut(&String,Point,4,"UInt")


Would that work? Or would I have to change the type or anything like that?

Well, strings are a bit special here. Strings are representated as numbers in the memory - look after ASCII Table to understand.) As TLM joked about (:mrgreen:), you have to test against NULL:

As I said before, every type needs to have a defined length in the memory. But C strings don't have that. The address of a string is the pointer to the first byte - the first char.
So how does we know the strings length? We have to read byte for byte (type char) - until we reach a NULL Byte. NULL Bytes terminating a string.

You can test this:



Code:
Var := "Hello World"

MsgBox % Var ;disp: Hello World

NumPut(0,Var,6,"char")  ;overwrite Byte 6 with NULL, this terminates the string.

MsgBox % Var ;disp: Hello

ExitApp

Its important to understand that "World" is not erased from the memory - it only lies behind the NULL byte and is still accessible with Memoryoperators like numget().

_________________
http://securityvision.ch
AHK 2D GAME ENGINE


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 19th, 2010, 5:37 pm 
Offline

Joined: February 13th, 2010, 3:52 pm
Posts: 175
Thanks for the explanation. And thanks also for the link TLM, looks good, that'll give me something to read this evening :)

EDIT: Woop, thanks to you guys and that post TLM linked to, I have just written my first successful (and quite pointless, but it was a learning experience) DllCall. Thanks. I now know much more about this sort of stuff.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 28th, 2010, 2:53 am 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6074
Location: San Diego, California
svi wrote:
It can be done in much simplier way.
You can use the following script to test which menu item selections [EDIT: actually highlightings] are detected (beep if not) by pressing q (I use that as a hotkey on my test scripts, because it's not used in the Finnish language).

Hi svi,
I sure took a long time getting back to this thread. :oops:
I don't see how your code help to know what the top level menu selection was.
For example in Notepad: File->Open...
becomes just "&Open... Ctrl+O"

So if I wanted to capture the menu selection to repeat it, i don't know what menu to start with, such as "File", "Edit","Format" ...

Do you have anything for this part of the selection process?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: chaosad, jrav and 20 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group