Sign in to follow this  
Followers 0
engine

Store a pointer inside a dword data structure

12 posts in this topic

Hi.

I am working with data structures that have pointers to strings and dwords. Something like this:

$tStruct = DllStructCreate("ptr[2];dword[7]")oÝ÷ Øz0z÷«Ýý²j+'½éâz{_¢¹¶¬y«­¢+ØÀÌØíÑMÑÉÕÐô±±MÑÉÕÑ
ÉÑ ÅÕ½ÐíݽÉlåtÅÕ½Ðì¤oÝ÷ ØZ+¶¬jez·²í«H«Þ¶Þ¥æ­¶¬¶»¶êÞiÇ«µ¨§jj.Ú¶)°·­ß۲˦zØ^jj.Ú¶)²+,¶Þv)Ú½ªâi¹^Ó~±N¬Â¥u·­ë-®ç-º·ºÚ"µÍÌÍÝÝXÝHÝXÝÜX]J    ][ÝÙÛÜÉ][ÝÈ  [ÈH
    ÌÍÞ  [È ][Ý×I][ÝÊ

So a dword is by definition an unsigned 32 bit integer. Under my observations a pointer seems to be an unsigned integer. My problem is that I don't know if the length of a pointer fits inside a 32 bit length. If true a dword could store a pointer.

Any help is appreciated.


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites



I don't think you will have a problem with that untill you get on a 64 bit OS where pointers are obviously 64 bit.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Thanks.

So on 32 bit OS, pointers are 32 bit. On 64 bit OS, pointers are 64 bit. Correct?

OK. I want my functions to work on the greatest number of OS possible. So I will think about another solution.


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks.

So on 32 bit OS, pointers are 32 bit. On 64 bit OS, pointers are 64 bit. Correct?

OK. I want my functions to work on the greatest number of OS possible. So I will think about another solution.

Yes. But you can also store a 32 bit pointer in a 64 bit data type.

32-bit pointer.

char *mystring = "hello world";
DWORD address = (DWORD)mystring; //address now stores the numeric memory address of my variable, mystring.

64-bit pointer (using this will work on both 32-bit systems and 64-bit systems)

char *mystring = "hello world";
__int64 address = (__int64)mystring; //same thing..

Both work. The second code will also work on 64 bit processors.

Edited by cppman

Share this post


Link to post
Share on other sites

In AutoIt documentation it's written under "DllStructCreate":

ptr 32bit(4bytes) integer

also

int_ptr 32 or 64bit signed integer (depending on if the x86 or x64 version of AutoIt is used)

So, should I use "ptr" or "int_ptr"?


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

Yes. But you can also store a 32 bit pointer in a 64 bit data type.

32-bit pointer.

char *mystring = "hello world";
DWORD address = (DWORD)mystring; //address now stores the numeric memory address of my variable, mystring.

64-bit pointer (using this will work on both 32-bit systems and 64-bit systems)

char *mystring = "hello world";
__int64 address = (__int64)mystring; //same thing..

Both work. The second code will also work on 64 bit processors.

Thanks.

Unfortunately that wont work on my case. I am reading an existing byte data structure that consists on structures like the ones I mentioned above. So the pointer 32 bit or 64 bit is already defined on that byte data structure.

Regards.


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

In AutoIt documentation it's written under "DllStructCreate":

also

So, should I use "ptr" or "int_ptr"?

But use an unsigned one (or a "ulong_ptr", they are the same thing).

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks.

Unfortunately that wont work on my case. I am reading an existing byte data structure that consists on structures like the ones I mentioned above. So the pointer 32 bit or 64 bit is already defined on that byte data structure.

Regards.

I'm confused. It that doesn't work, why would it work if you were to use "ulong_ptr"? A DWORD is 32 bits. An __int64 is 64 bits. If the pointer inside the struct is all ready a 32 bit pointer, you can still assign that pointer to a 64 bit data type (an __int64).

Just think of a pointer as a number (that's all it is).

The maximum number a 32 bit pointer can hold is: 4,294,967,295 (that's why the maximum amount of memory on a 32-bit processor is 4GB)

The maximum number a 64 bit pointer can hold is: 18,446,744,073,709,551,615

Edited by cppman

Share this post


Link to post
Share on other sites

I'm confused. It that doesn't work, why would it work if you were to use "ulong_ptr"? A DWORD is 32 bits. An __int64 is 64 bits. If the pointer inside the struct is all ready a 32 bit pointer, you can still assign that pointer to a 64 bit data type (an __int64).

I am sorry. It would take too long to explain it properly.

It just doesn't work.


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

I'm confused. It that doesn't work, why would it work if you were to use "ulong_ptr"? A DWORD is 32 bits. An __int64 is 64 bits. If the pointer inside the struct is all ready a 32 bit pointer, you can still assign that pointer to a 64 bit data type (an __int64).

Just think of a pointer as a number (that's all it is).

The maximum number a 32 bit pointer can hold is: 4,294,967,295 (that's why the maximum amount of memory on a 32-bit processor is 4GB)

The maximum number a 64 bit pointer can hold is: 18,446,744,073,709,551,615

Actually "ulong_ptr" works, "uint64" doesn't.

I guess i can use "ulong_ptr" or "uint_ptr". They are the same, right?


My contributions:Local account UDF Registry UDFs DriverSigning UDF Windows Services UDF [url="http://www.autoitscript.com/forum/index.php?showtopic=81880"][/url]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Actually "ulong_ptr" works, "uint64" doesn't.

I guess i can use "ulong_ptr" or "uint_ptr". They are the same, right?

Yeah, they are both either 32 or 64 bits.

As for it not working, I'm not sure why. You can store a 32-bit pointer inside a 64-bit integer.

Edited by cppman

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