16004 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
16004 #KEY_WOW64_64KEY to force access to the 64Bit Windows key, |
16005 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
16005 #KEY_WOW64_32KEY to force access to the 32Bit Windows key, |
16006 or nil, to access the key (32/64) for the current application. |
16006 or nil, to access the key (32/64) for the current application. |
16007 " |
16007 " |
16008 |
16008 |
16009 |subKeyStringZ errorNumber| |
16009 |subKeyStringUtf16Z errorNumber| |
16010 |
16010 |
16011 subKeyStringZ := subKeyString asUnicode16StringZ. |
16011 subKeyStringUtf16Z := subKeyString asUnicode16StringZ. |
16012 |
16012 |
16013 %{ |
16013 %{ |
16014 /* |
16014 /* |
16015 * Following is a little tricky. To be able to access 32bit / 64bit keys |
16015 * Following is a little tricky. To be able to access 32bit / 64bit keys |
16016 * we need to use RegDeleteKeyExW() which not however available on (old)\ |
16016 * we need to use RegDeleteKeyExW() which not however available on (old)\ |
16019 * To do so, call RegDeleteKeyExW() indirectly via a function pointer |
16019 * To do so, call RegDeleteKeyExW() indirectly via a function pointer |
16020 * obtained by GetProcAddress(). If GetProcAddress() fails - meaning |
16020 * obtained by GetProcAddress(). If GetProcAddress() fails - meaning |
16021 * we're running on such old Windows - we call old RegDeleteKeyW(). |
16021 * we're running on such old Windows - we call old RegDeleteKeyW(). |
16022 */ |
16022 */ |
16023 static int initialized = 0; |
16023 static int initialized = 0; |
16024 static LONG (WINAPI *RegDeleteKeyExWPtr)(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved) = NULL; |
16024 static LONG (WINAPI *RegDeleteKeyExWPtr)(HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved) = NULL; |
16025 if (!initialized) { |
16025 if (!initialized) { |
16026 initialized = 1; |
16026 initialized = 1; |
16027 HMODULE advapi32 = LoadLibrary("advapi32.dll"); |
16027 HMODULE advapi32 = LoadLibrary("advapi32.dll"); |
16028 if (!advapi32) { |
16028 if (!advapi32) { |
16029 /* |
16029 /* |
16030 * Hmm, failed to load Advapi32.dll, can this happen? |
16030 * Hmm, failed to load Advapi32.dll, can this happen? |
16031 */ |
16031 */ |
16032 errorNumber = __MKSMALLINT(GetLastError()); |
16032 errorNumber = __MKSMALLINT(GetLastError()); |
16033 goto out; |
16033 goto out; |
16034 } |
16034 } |
16035 RegDeleteKeyExWPtr = GetProcAddress(advapi32, "RegDeleteKeyExW"); |
16035 RegDeleteKeyExWPtr = (LONG (*) (HKEY hKey, LPCTSTR lpSubKey, REGSAM samDesired, DWORD Reserved)) GetProcAddress( |
|
16036 advapi32, "RegDeleteKeyExW"); |
16036 } |
16037 } |
16037 |
16038 |
16038 HKEY myKey, subKey = 0; |
16039 HKEY myKey, subKey = 0; |
16039 int _retVal; |
16040 int _retVal; |
16040 int _flags = 0; |
16041 int _flags = 0; |
16049 goto out; |
16050 goto out; |
16050 } |
16051 } |
16051 } |
16052 } |
16052 |
16053 |
16053 if (__isExternalAddressLike(__INST(handle)) |
16054 if (__isExternalAddressLike(__INST(handle)) |
16054 && __isUnicode16String(subKeyStringZ)) { |
16055 && __isUnicode16String(subKeyStringUtf16Z)) { |
16055 myKey = (HKEY)__externalAddressVal(__INST(handle)); |
16056 myKey = (HKEY)__externalAddressVal(__INST(handle)); |
16056 if (RegDeleteKeyExWPtr) { |
16057 if (RegDeleteKeyExWPtr) { |
16057 _retVal = RegDeleteKeyExWPtr(myKey, |
16058 _retVal = RegDeleteKeyExWPtr(myKey, |
16058 __unicode16StringVal(subKeyStringZ), |
16059 (LPCTSTR) __unicode16StringVal(subKeyStringUtf16Z), |
16059 _flags, |
16060 _flags, |
16060 0); // reserved |
16061 0); // reserved |
16061 } else { |
16062 } else { |
16062 /* |
16063 /* |
16063 * Some old Windows without RegDeleteKeyExW() such as |
16064 * Some old Windows without RegDeleteKeyExW() such as |
16066 * if no flags are passed, i.e., `flags` parameter is nil. |
16067 * if no flags are passed, i.e., `flags` parameter is nil. |
16067 * This is to avoid silent failures when one explicitly asks |
16068 * This is to avoid silent failures when one explicitly asks |
16068 * for 32bit or 64bit view on Windows that does not support |
16069 * for 32bit or 64bit view on Windows that does not support |
16069 * RegDeleteKeyExW(). |
16070 * RegDeleteKeyExW(). |
16070 */ |
16071 */ |
16071 if (flags != nil) { |
16072 if (flags != nil) //if flag specified then return ERROR_INVALID_PARAMETER |
16072 errorNumber = __MKSMALLINT(-1); // really stupid, should do better |
16073 _retVal = ERROR_INVALID_PARAMETER; |
16073 goto out; |
16074 else |
16074 } |
16075 _retVal = RegDeleteKeyW(myKey, __unicode16StringVal(subKeyStringUtf16Z)); |
16075 _retVal = RegDeleteKeyW(myKey, __unicode16StringVal(subKeyStringZ)); |
|
16076 } |
16076 } |
16077 if (_retVal == ERROR_SUCCESS) { |
16077 if (_retVal == ERROR_SUCCESS) { |
16078 RETURN (true); |
16078 RETURN (true); |
16079 } |
16079 } |
16080 if ((_retVal != ERROR_PATH_NOT_FOUND) |
16080 if ((_retVal != ERROR_PATH_NOT_FOUND) |