martin Posted June 5, 2008 Share Posted June 5, 2008 (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 June 5, 2008 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 More sharing options...
jwseek Posted June 5, 2008 Share Posted June 5, 2008 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 More sharing options...
Moderators SmOke_N Posted June 5, 2008 Moderators Share Posted June 5, 2008 @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 More sharing options...
jwseek Posted June 5, 2008 Share Posted June 5, 2008 @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 More sharing options...
monoceres Posted June 5, 2008 Share Posted June 5, 2008 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! Link to comment Share on other sites More sharing options...
evilertoaster Posted June 5, 2008 Share Posted June 5, 2008 @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 More sharing options...
martin Posted June 5, 2008 Author Share Posted June 5, 2008 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 More sharing options...
Siao Posted June 5, 2008 Share Posted June 5, 2008 (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 June 5, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
martin Posted June 5, 2008 Author Share Posted June 5, 2008 "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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now