This is the simplified scenario, in Delphi 7:
procedure TMyClass.InternalGetData;
var
pRequest: HINTERNET;
/// nested Callback
procedure HTTPOpenRequestCallback(hInet: HINTERNET; Context: PDWORD; Status: DWORD; pInformation: Pointer; InfoLength: DWORD); stdcall;
begin
// [...] make something with pRequest
end;
begin
pRequest := HTTPOpenRequest(...);
// [...]
if (InternetSetStatusCallback(pRequest, @HTTPOpenRequestCallback) = PFNInternetStatusCallback(INTERNET_INVALID_STATUS_CALLBACK)) then
raise Exception.Create('InternetSetStatusCallback failed');
// [...]
end;
The whole thing seems to work fine, but is it really correct and safe?
I'd like to have it encapsulated this way because it's more readable and clean. My doubt is whether the nested procedure is a simple, normal procedure or not, so that it can have its own calling convention (stdcall
) and safely reference outer method's local variables (pRequest
).
Thank you.
pRequest
seems begging for errors. :-) – Tendency