Sign in to follow this  
Followers 0
martin

What is the difference between int* and ptr in a dll call?

9 posts in this topic

#1 ·  Posted (edited)

If I use "ptr" as in the line which follows it works

dllcall("winspool.drv","int","GetDefaultPrinter","str",'',"ptr",DllStructGetPtr($namesize))

If I use "int*" or "dword*" it doesn't

dllcall("winspool.drv","int","GetDefaultPrinter","str",'',"int*",DllStructGetPtr($namesize))

According to msdn the parameter should be a pointer to a dword. I can create the struct as a dword, or as an int and the dllcall succeeds if I use "ptr" for the parameter type, but neither "dword*" nor "int*" works.

I thought both would work.

Can anyone explain the difference to me?

Edited by martin

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



If I use "ptr" as in the line which follows it works

dllcall("winspool.drv","int","GetDefaultPrinter","str",'',"ptr",DllStructGetPtr($namesize))

If I use "int*" or "dword*" it doesn't

dllcall("winspool.drv","int","GetDefaultPrinter","str",'',"int*",DllStructGetPtr($namesize))

According to msdn the parameter should be a pointer to a dword. I can create the struct as a dword, or as an int and the dllcall succeeds if I use "ptr" for the parameter type, but neither "dword*" nor "int*" works.

I thought both would work.

Can anyone explain the difference to me?

dword* and int* are specified types of pointers. They allocate a specific amount of memory relative to those variable types. Creating a general "pointer" type to reference memory is much more likely to success as it's not forcing a specified type on unknown memory. This is why people hate working with pointers, they don't make a whole lot of sense.

Share this post


Link to post
Share on other sites

@Martin, I ran into this issue the other day myself.

@jwseek, if the param calls for a dword ptr, then the memory expected to be passed would that of a dword ptr I would think.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

@Martin, I ran into this issue the other day myself.

@jwseek, if the param calls for a dword ptr, then the memory expected to be passed would that of a dword ptr I would think.

Yeah, but a pointer to a dword and a dword pointer are different things. One simply points to a memory location that happens to contain a dword while the other is allocated memory the size of a dword variable. I think. I could be completely wrong.

Share this post


Link to post
Share on other sites

I'm just speculating but couldn't the keyword be reference?

Because like Valik pointed out to me in this topic pointers and references just isn't the same.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

@jwseek, if the param calls for a dword ptr, then the memory expected to be passed would that of a dword ptr I would think.

That's my understanding as well, and since 'ptr' is described as "a general pointer (void *)" it would make sense for it not to work, since void* and dword* are certianly not the same...

Share this post


Link to post
Share on other sites

That's my understanding as well, and since 'ptr' is described as "a general pointer (void *)" it would make sense for it not to work, since void* and dword* are certianly not the same...

Well what's been said so far hasn't helped my understanding. I thought a pointer was just an address where a variable was stored. In other words, in a 32 bit system passing a pointer is just giving a 32 bit value no matter what the pointer is for. The difference only is how that address is used to read the data (I thought). Since I'm wrong it would help the way I understand things if I knew what was being passed by "ptr" and what by "dword*" and what by "int*".

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

#8 ·  Posted (edited)

"ptr" is pointer - an address of whatever memory location you specify.

"int*" is internally controlled Int32 variable. You can set it to a number, and you can read it back from return array. Serves as poor man's ByRef.

Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

"ptr" is pointer, and address of whatever memory location you specify.

"int*" is internally controlled Int32 variable. You can set it to a number, and you can read it back from return array. Serves as poor man's ByRef.

Ah, so if I need too pass the C equivalent of &Var I should always use "ptr", and when I use "int*" then the receiving function is effectively directly controlling the variable? So "int*" is not like the C declaration int *var then?

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

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