Issue #252: Smalltak/X is writing Windows Registry only in ASCII but registry is UTF16
- refactor deleteValueNamed: to unicode version
- minor: indent comments that needed
--- a/Win32OperatingSystem.st Wed Dec 05 14:21:11 2018 +0100
+++ b/Win32OperatingSystem.st Thu Dec 06 14:46:59 2018 +0100
@@ -16103,40 +16103,40 @@
"
!
-remoteKeyOnHost:hostNameString
+remoteKeyOnHost:hostName
"return the corresponding registry entry from
a remote computers registry.
Note: The registry key must be form a predefined list defined by Microsoft."
|hostNameUtf16Z newEntry remoteHandle errorNumber|
- hostNameUtf16Z := hostNameString notEmptyOrNil ifTrue:[hostNameString asUnicode16StringZ].
+ hostNameUtf16Z := hostName notEmptyOrNil ifTrue:[hostName asUnicode16StringZ].
%{
HKEY myKey, remoteKey = 0;
int _retVal;
-/* Notes from MSDN:
- * link: https://docs.microsoft.com/en-us/windows/desktop/api/winreg/nf-winreg-regconnectregistryw
- *
- * 1) RegConnectRegistry requires the Remote Registry service to be running on the remote computer.
- * By default, this service is configured to be started manually. To configure the Remote Registry
- * service to start automatically, run Services.msc and change the Startup Type of the service to Automatic.
- *
- * 2) If the computer is joined to a workgroup and the "Force network logons using local accounts to authenticate as
- * Guest" policy is enabled, the function fails. Note that this policy is enabled by default if the computer is joined
- * to a workgroup.
- *
- * 3) If the current user does not have proper access to the remote computer, the call to RegConnectRegistry fails. To connect
- * to a remote registry, call LogonUser with LOGON32_LOGON_NEW_CREDENTIALS and ImpersonateLoggedOnUser before calling
- * RegConnectRegistry.
- *
- * 4) myKey must be a predefined registry handle.
- * more at: https://docs.microsoft.com/en-us/windows/desktop/SysInfo/predefined-keys
- *
- * 5) When a handle returned by RegConnectRegistry is no longer needed, it should be closed by calling RegCloseKey. (done by registerForFinaliation)
- *
- */
+ /* Notes from MSDN:
+ * link: https://docs.microsoft.com/en-us/windows/desktop/api/winreg/nf-winreg-regconnectregistryw
+ *
+ * 1) RegConnectRegistry requires the Remote Registry service to be running on the remote computer.
+ * By default, this service is configured to be started manually. To configure the Remote Registry
+ * service to start automatically, run Services.msc and change the Startup Type of the service to Automatic.
+ *
+ * 2) If the computer is joined to a workgroup and the "Force network logons using local accounts to authenticate as
+ * Guest" policy is enabled, the function fails. Note that this policy is enabled by default if the computer is joined
+ * to a workgroup.
+ *
+ * 3) If the current user does not have proper access to the remote computer, the call to RegConnectRegistry fails. To connect
+ * to a remote registry, call LogonUser with LOGON32_LOGON_NEW_CREDENTIALS and ImpersonateLoggedOnUser before calling
+ * RegConnectRegistry.
+ *
+ * 4) myKey must be a predefined registry handle.
+ * more at: https://docs.microsoft.com/en-us/windows/desktop/SysInfo/predefined-keys
+ *
+ * 5) When a handle returned by RegConnectRegistry is no longer needed, it should be closed by calling RegCloseKey. (done by registerForFinaliation)
+ *
+ */
if (__isExternalAddressLike(__INST(handle)) && __isUnicode16String(hostNameUtf16Z)) {
myKey = (HKEY)__externalAddressVal(__INST(handle));
@@ -16549,26 +16549,38 @@
"
!
-deleteValueNamed:aValueName
+deleteValueNamed:name
"delete a value.
Return true on success."
- |errorNumber|
-
-%{
- HKEY myKey;
+ |nameUtf16Z errorNumber|
+
+ "/ name must be a string
+ name isString ifFalse: [
+ Transcript showCR: 'The registry value name must be a String!!'.
+ ^ false
+ ].
+
+ "/ adding terminating null into empty string
+ name notNil ifTrue:[
+ nameUtf16Z := name isEmpty ifTrue:[(name, (Character codePoint: 0)) asUnicode16String] "/ needed for defaultValue
+ ifFalse:[name asUnicode16StringZ]
+ ].
+
+%{
+ HKEY myKey = 0;
int _retVal;
if (__isExternalAddressLike(__INST(handle))
- && __isStringLike(aValueName)) {
+ && __isUnicode16String(nameUtf16Z)) {
myKey = (HKEY)__externalAddressVal(__INST(handle));
- if ((_retVal = RegDeleteValueA(myKey, __stringVal(aValueName))) == ERROR_SUCCESS) {
- RETURN (true);
- }
- if ((_retVal != ERROR_PATH_NOT_FOUND)
- && (_retVal != ERROR_FILE_NOT_FOUND)) {
- errorNumber = __MKSMALLINT(_retVal);
- }
+ if ((_retVal = RegDeleteValueW(myKey, __unicode16StringVal(nameUtf16Z))) == ERROR_SUCCESS) {
+ RETURN (true);
+ }
+ if ((_retVal != ERROR_PATH_NOT_FOUND)
+ && (_retVal != ERROR_FILE_NOT_FOUND)) {
+ errorNumber = __MKSMALLINT(_retVal);
+ }
}
%}.
errorNumber notNil ifTrue:[
@@ -16963,14 +16975,14 @@
].
"/ name asUnicodeString and null terminated
name notNil ifTrue:[
- name isEmpty ifTrue:[nameUtf16Z := (name, (Character codePoint: 0)) asUnicode16String] "/ needed for defaultValue:
- ifFalse:[nameUtf16Z := name asUnicode16StringZ]
+ nameUtf16Z := name isEmpty ifTrue:[(name, (Character codePoint: 0)) asUnicode16String] "/ needed for defaultValue:
+ ifFalse:[name asUnicode16StringZ]
].
"/ data asUnicode16String and null terminated
data notNil ifTrue:[
data isString ifTrue:[
- data isEmpty ifTrue:[dataUtf16Z := (data, (Character codePoint: 0)) asUnicode16String] "/ for empty data strings
- ifFalse:[dataUtf16Z := data asUnicode16StringZ]
+ dataUtf16Z := data isEmpty ifTrue:[(data, (Character codePoint: 0)) asUnicode16String] "/ for empty data strings
+ ifFalse:[ data asUnicode16StringZ]
].
data isArray ifTrue:[
dataUtf16Z := data collect:[:eachString | "/ for every Array member to be null terminated
@@ -17396,7 +17408,6 @@
%}.
"Created: / 19.5.1999 / 21:45:05 / cg"
-
! !
!Win32OperatingSystem::TextMetricsStructure class methodsFor:'instance creation'!