Documentation of WinHttpGetIEProxyConfigForCurrentUser says:
The caller must free the lpszProxy, lpszProxyBypass and lpszAutoConfigUrl strings in the WINHTTP_CURRENT_USER_IE_PROXY_CONFIG structure if they are non-NULL. Use GlobalFree to free the strings.
I wrote the following code (Delphi 10.3.2):
var
VConfig: TWinHttpCurrentUserIEProxyConfig;
begin
FillChar(VConfig, SizeOf(VConfig), 0);
if not WinHttpGetIEProxyConfigForCurrentUser(VConfig) then begin
RaiseLastOSError;
end;
...
if VConfig.lpszAutoConfigUrl <> nil then begin
GlobalFree(VConfig.lpszAutoConfigUrl); // <-- Error
end;
and got an error:
[dcc32 Error] E2010 Incompatible types: 'NativeUInt' and 'PWideChar'
Questions:
should I type-cast
PWideChar
toNativeUInt
?can I use
GlobafFreePtr
instead ofGlobafFree
(it acceptsPWideChar
and works fine in my tests)?
GlobalFreePtr
callsGlobalHandle
to get anHGLOBAL
from a pointer, thenGlobalUnlock
to unlock that handle, thenGlobalFree
. All the examples I see online callGlobalFree
directly on the pointer. My guess is that, these days at least,GlobalHandle
returns its input value directly, in other words theHGLOBAL
is the same thing as the pointer. My suggestion is that you callGlobalFree
directly, and hence cast the pointer toHGLOBAL
.GlobalFree(HGLOBAL(...))
- David HeffernanGlobalFreePtr
should be used. So, I think it would be safer to useGlobalFreePtr
in all cases. - zed