Issue #252: Smalltak/X is writing Windows Registry only in ASCII but registry is UTF16
deleteSubKeyNamed:flags:
refactorings
- better naming convention of Unicode16String
- improved error handling when flags are specified via ERROR_INVALID_PARAMETER
to avoid warning messages:
- casting from FARPROC GetProcAddress() to (LONG (*) (HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved)) GetProcAddress() (could be done shorter via typedef)
- in RegDeleteKeyExWPtr cast from __unicode16StringVal -> (LPCTSTR) __unicode16StringVal(subKeyStringUtf16Z)
--- a/Win32OperatingSystem.st Fri Dec 07 09:40:11 2018 +0100
+++ b/Win32OperatingSystem.st Fri Dec 07 13:41:02 2018 +0100
@@ -16006,9 +16006,9 @@
or nil, to access the key (32/64) for the current application.
"
- |subKeyStringZ errorNumber|
-
- subKeyStringZ := subKeyString asUnicode16StringZ.
+ |subKeyStringUtf16Z errorNumber|
+
+ subKeyStringUtf16Z := subKeyString asUnicode16StringZ.
%{
/*
@@ -16021,7 +16021,7 @@
* we're running on such old Windows - we call old RegDeleteKeyW().
*/
static int initialized = 0;
- static LONG (WINAPI *RegDeleteKeyExWPtr)(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved) = NULL;
+ static LONG (WINAPI *RegDeleteKeyExWPtr)(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved) = NULL;
if (!initialized) {
initialized = 1;
HMODULE advapi32 = LoadLibrary("advapi32.dll");
@@ -16032,7 +16032,8 @@
errorNumber = __MKSMALLINT(GetLastError());
goto out;
}
- RegDeleteKeyExWPtr = GetProcAddress(advapi32, "RegDeleteKeyExW");
+ RegDeleteKeyExWPtr = (LONG (*) (HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved)) GetProcAddress(
+ advapi32, "RegDeleteKeyExW");
}
HKEY myKey, subKey = 0;
@@ -16051,11 +16052,11 @@
}
if (__isExternalAddressLike(__INST(handle))
- && __isUnicode16String(subKeyStringZ)) {
+ && __isUnicode16String(subKeyStringUtf16Z)) {
myKey = (HKEY)__externalAddressVal(__INST(handle));
if (RegDeleteKeyExWPtr) {
_retVal = RegDeleteKeyExWPtr(myKey,
- __unicode16StringVal(subKeyStringZ),
+ (LPCTSTR) __unicode16StringVal(subKeyStringUtf16Z),
_flags,
0); // reserved
} else {
@@ -16068,11 +16069,10 @@
* for 32bit or 64bit view on Windows that does not support
* RegDeleteKeyExW().
*/
- if (flags != nil) {
- errorNumber = __MKSMALLINT(-1); // really stupid, should do better
- goto out;
- }
- _retVal = RegDeleteKeyW(myKey, __unicode16StringVal(subKeyStringZ));
+ if (flags != nil) //if flag specified then return ERROR_INVALID_PARAMETER
+ _retVal = ERROR_INVALID_PARAMETER;
+ else
+ _retVal = RegDeleteKeyW(myKey, __unicode16StringVal(subKeyStringUtf16Z));
}
if (_retVal == ERROR_SUCCESS) {
RETURN (true);
@@ -16086,11 +16086,11 @@
%}.
errorNumber notNil ifTrue:[
- errorNumber == -1 ifTrue:[
+ errorNumber == 87 ifTrue:[ "/ 87 (0x57) ... ERROR_INVALID_PARAMETER
self primitiveFailed: '32/64bit registry view requested but no RegDeleteKeyExW(). Windows too old?'
- ] ifFalse:[
+ ].
(OperatingSystem errorHolderForNumber:errorNumber) reportError.
- ]
+
].
^ false