Re: null and native call question
On 2019-12-29 05:46, WFB wrote: Hi Todd, I am curious, what was the problem? I tried 0 in the first place and the script died. Though it has something to do with the 0 but obviously it has not. Hi Bill, I have a major rewrite underway for several of my modules. Hopefully I will post them her today for evaluation. On the "null and native call question", Native Call translates a zero into a C NULL for you. My run and die issue was not lpReserved being sent a NULL incorrectly. The culprit was M$ and lpType. https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw C++ LSTATUS RegQueryValueExW( HKEYhKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ); lpType A pointer to a variable that receives a code indicating the type of data stored in the specified value. For a list of the possible type codes, see Registry Value Types. The lpType parameter can be NULL if the type code is not required. I was sending lpType the value for REG_DWORD (0x0004) and sometimes REG_SZ (0x0001). This caused the call to die with no error message. The ONLY value of lpType that actually works is 0 (NULL). Ha! M$ STRIKES AGAIN! Good gracious I wasted and a lot of others helping me wasted a lot of time on this! AAHHH!!! -T
Re: null and native call question
Hi Todd, I am curious, what was the problem? I tried 0 in the first place and the script died. Though it has something to do with the 0 but obviously it has not. On Sun, 29 Dec 2019 at 10:31, ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > On 2019-12-29 00:28, ToddAndMargo via perl6-users wrote: > >>> On Fri, Dec 27, 2019 at 6:06 AM ToddAndMargo via perl6-users > >>> mailto:perl6-users@perl.org>> wrote: > >>> > >>> Hi All, > >>> > >>> https://docs.perl6.org/language/nativecall > >>> > >>>"As you may have predicted by now, a NULL pointer > >>>is represented by the type object of the struct type." > >>> > >>> > >>> > https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw > >>> > >>> > >>>C++ > >>>LSTATUS RegQueryValueExW( > >>> HKEYhKey, > >>> LPCWSTR lpValueName, > >>> LPDWORD lpReserved, > >>> LPDWORD lpType, > >>> LPBYTE lpData, > >>> LPDWORD lpcbData > >>>); > >>> > >>>lpReserved > >>>This parameter is reserved and must be NULL. > >>> > >>> With "native", how do I satisfy the "NULL" requirement? > >>> > >>> constant WCHAR := uint16; > >>> > >>> constant DWORD := int32; > >>> > >>> > >>> sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, > >>> DWORD is > >>> rw ) is native("Kernel32.dll") returns DWORD { * }; > >>> > >>> $RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32, > >>> REG_DWORD, > >>> $lpData, $lpcbData ); > >>> > >>> "int32" returns: > >>> > >>> Cannot unbox a type object (int32) to int in method > >>> CALL-ME at C:\rakudo\share\perl6\sources > >>> \947BDAB9F96E0E5FCCB383124F9 > >>> 23A6BF6F8D76B (NativeCall) line 587 > >>> > >>> > >>> Many thanks, > >>> -T > >>> > > > > On 2019-12-27 06:10, Brad Gilbert wrote: > >> A Null pointer is just a pointer that points to the address 0. > >> > >> So if you are dealing with it as an integer it will be 0. > > Hi Brad, > > Disregard my last post. I found a booboo somewhere else. > You were correct about the zero. > > Thank you! > > -T >
Re: null and native call question
On 2019-12-29 00:28, ToddAndMargo via perl6-users wrote: On Fri, Dec 27, 2019 at 6:06 AM ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: Hi All, https://docs.perl6.org/language/nativecall "As you may have predicted by now, a NULL pointer is represented by the type object of the struct type." https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw C++ LSTATUS RegQueryValueExW( HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ); lpReserved This parameter is reserved and must be NULL. With "native", how do I satisfy the "NULL" requirement? constant WCHAR := uint16; constant DWORD := int32; sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is rw ) is native("Kernel32.dll") returns DWORD { * }; $RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32, REG_DWORD, $lpData, $lpcbData ); "int32" returns: Cannot unbox a type object (int32) to int in method CALL-ME at C:\rakudo\share\perl6\sources \947BDAB9F96E0E5FCCB383124F9 23A6BF6F8D76B (NativeCall) line 587 Many thanks, -T On 2019-12-27 06:10, Brad Gilbert wrote: A Null pointer is just a pointer that points to the address 0. So if you are dealing with it as an integer it will be 0. Hi Brad, Disregard my last post. I found a booboo somewhere else. You were correct about the zero. Thank you! -T
Re: null and native call question
On Fri, Dec 27, 2019 at 6:06 AM ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: Hi All, https://docs.perl6.org/language/nativecall "As you may have predicted by now, a NULL pointer is represented by the type object of the struct type." https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw C++ LSTATUS RegQueryValueExW( HKEYhKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ); lpReserved This parameter is reserved and must be NULL. With "native", how do I satisfy the "NULL" requirement? constant WCHAR := uint16; constant DWORD := int32; sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is rw ) is native("Kernel32.dll") returns DWORD { * }; $RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32, REG_DWORD, $lpData, $lpcbData ); "int32" returns: Cannot unbox a type object (int32) to int in method CALL-ME at C:\rakudo\share\perl6\sources \947BDAB9F96E0E5FCCB383124F9 23A6BF6F8D76B (NativeCall) line 587 Many thanks, -T On 2019-12-27 06:10, Brad Gilbert wrote: A Null pointer is just a pointer that points to the address 0. So if you are dealing with it as an integer it will be 0. Hi Brad, Sending a zero to it causes the program to exit with no error code. The offending line is: $RtnCode = RegQueryValueExW( $Handle, $lpValueName, 0, REG_DWORD, $lpData, $lpcbData ); Sending it a zero: say "RegQueryValueExW"; sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is rw ) is native("Kernel32.dll") returns DWORD { * }; say "1"; $RtnCode = RegQueryValueExW( $Handle, $lpValueName, 0, REG_DWORD, $lpData, $lpcbData ); say "2"; say "RegQueryValueExW RtnCode $RtnCode (6 = The handle is invalid; 87 = ERROR_INVALID_PARAMETER)\nlpData pointer $lpData\nlpcbData data length $lpcbData\n"; RegQueryValueExW 1 Note that it dies without an error code. Sending it a one: say "RegQueryValueExW"; sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is rw ) is native("Kernel32.dll") returns DWORD { * }; say "1"; $RtnCode = RegQueryValueExW( $Handle, $lpValueName, 1, REG_DWORD, $lpData, $lpcbData ); say "2"; say "RegQueryValueExW RtnCode $RtnCode (6 = The handle is invalid; 87 = ERROR_INVALID_PARAMETER)\nlpData pointer $lpData\nlpcbData data length $lpcbData\n"; RegQueryValueExW 1 2 RegQueryValueExW RtnCode 87 (6 = The handle is invalid; 87 = ERROR_INVALID_PARAMETER) lpData pointer 0 lpcbData data length 0 I can't win. :'( Thank you for the help. -T -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: null and native call question
A Null pointer is just a pointer that points to the address 0. So if you are dealing with it as an integer it will be 0. On Fri, Dec 27, 2019 at 6:06 AM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > Hi All, > > https://docs.perl6.org/language/nativecall > > "As you may have predicted by now, a NULL pointer > is represented by the type object of the struct type." > > > https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw > > C++ > LSTATUS RegQueryValueExW( > HKEYhKey, > LPCWSTR lpValueName, > LPDWORD lpReserved, > LPDWORD lpType, > LPBYTE lpData, > LPDWORD lpcbData > ); > > lpReserved > This parameter is reserved and must be NULL. > > With "native", how do I satisfy the "NULL" requirement? > > constant WCHAR := uint16; > > constant DWORD := int32; > > > sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is > rw ) is native("Kernel32.dll") returns DWORD { * }; > > $RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32, REG_DWORD, > $lpData, $lpcbData ); > > "int32" returns: > > Cannot unbox a type object (int32) to int in method > CALL-ME at C:\rakudo\share\perl6\sources \947BDAB9F96E0E5FCCB383124F9 > 23A6BF6F8D76B (NativeCall) line 587 > > > Many thanks, > -T >
null and native call question
Hi All, https://docs.perl6.org/language/nativecall "As you may have predicted by now, a NULL pointer is represented by the type object of the struct type." https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw C++ LSTATUS RegQueryValueExW( HKEYhKey, LPCWSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData ); lpReserved This parameter is reserved and must be NULL. With "native", how do I satisfy the "NULL" requirement? constant WCHAR := uint16; constant DWORD := int32; sub RegQueryValueExW( DWORD, WCHARS, DWORD, DWORD, DWORD is rw, DWORD is rw ) is native("Kernel32.dll") returns DWORD { * }; $RtnCode = RegQueryValueExW( $Handle, $lpValueName, int32, REG_DWORD, $lpData, $lpcbData ); "int32" returns: Cannot unbox a type object (int32) to int in method CALL-ME at C:\rakudo\share\perl6\sources \947BDAB9F96E0E5FCCB383124F9 23A6BF6F8D76B (NativeCall) line 587 Many thanks, -T