Jump to content

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


Recommended Posts

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.
Link to comment
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.
Link to comment
Share on other sites

  • Moderators

@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.

Link to comment
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.

Link to comment
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...
Link to comment
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.
Link to comment
Share on other sites

"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"

Link to comment
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.
Link to comment
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
 Share

  • Recently Browsing   0 members

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