• Page:
  • 1
  • 2

TOPIC: Winhttp in Delphi tokyo 10.2.3

Winhttp in Delphi tokyo 10.2.3 3 months 1 week ago #13550

I found that my code from 10.1 can not be compiled in 10.2 when using the winhttp api
I noticed that there are changes in winapi.WinHttp in 10.2.3 : eg
function WinHttpQueryDataAvailable(hRequest: HINTERNET; lpdwNumberOfBytesAvailable: LPDWORD): BOOL; stdcall;
In 10.1 the same function is declared as:
function WinHttpQueryDataAvailable(hRequest: HInternet; var lpdwNumberofBytesAvailable): BOOL;
The problem is that using a DWORD variable and passing its pointer gives unpredictable results.....

Please Log in or Create an account to join the conversation.

Winhttp in Delphi tokyo 10.2.3 2 months 1 week ago #13763

The 10.1 declaration is technically wrong. Even when using a 'var' parameter, it should have been typed as a DWORD at least, not left untyped. And was it actually missing the 'stdcall' calling convention, or did you simply omit that?

The 10.2 declaration is more inline with the actual declaration used by the SDK.

The 'lpdwNumberOfBytesAvailable' parameter must be set to nil when WinHTTP is used in asynchronous mode. That is easier to do with a pointer parameter than with a 'var' parameter.

Passing a pointer to a variable is the correct solution in 10.2. What problems exactly are you having when you do it? Please be more specific.
The following user(s) said Thank You: Dimitris

Please Log in or Create an account to join the conversation.

Winhttp in Delphi tokyo 10.2.3 2 months 1 week ago #13766

I fully agree with you, and the stdcall exists in 10.1
In 32bit VCL application, I I pass a pointer to a cardinal variable and I get unpredictable results
I noticed now that probably cardinal is not the same thing with longword for the compiler, so I will test it again....
thank you for your response

Please Log in or Create an account to join the conversation.

Winhttp in Delphi tokyo 10.2.3 2 months 4 days ago #13790

Dimitris wrote: I pass a pointer to a cardinal variable and I get unpredictable results


Such as? Can you be more specific?

Dimitris wrote: I noticed now that probably cardinal is not the same thing with longword for the compiler


In 32-bit, it is. However, the API is expecting a pointer to a DWORD, so you really should be using that instead of Cardinal.
The following user(s) said Thank You: Dimitris

Please Log in or Create an account to join the conversation.

Winhttp in Delphi tokyo 10.2.3 1 month 4 weeks ago #13834

I try to test today the situation. I changed all cardinals to Dwords.
I followed the header declarations in winapi.winhttp and I noticed the following:
Just before calling the WinHttpReadData everything is OK in my debugging. After that nearly all variables are garbage.
but....
a. I use a pointer from an allocmem of 8K as winhtttp docs suggest here even the needed size of the data as returned by WinHttpQueryDataAvailable is less than 300bytes.
b. The result from WinHttpReadData is true

I tried to change the winapi.winhttp and have the declaration from DELPHI 10.1 but even if I change it from notepad and Delphi IDE requests to reload it, the syntax is found incorrect during compile. Where is the header file that it is used during compile?
The one that I changed is in C:\Program Files (x86)\Embarcadero\Studio\19.0\source\rtl\win

I feel it is not a problem from the declaration anymore......

Please Log in or Create an account to join the conversation.

Winhttp in Delphi tokyo 10.2.3 1 month 4 weeks ago #13839

Dimitris wrote: Just before calling the WinHttpReadData everything is OK in my debugging. After that nearly all variables are garbage.


That implies that you are not calling WinHttpReadData() correctly and thus causing memory corruption. What does your code actually look like?

Dimitris wrote: a. I use a pointer from an allocmem of 8K as winhtttp docs suggest here even the needed size of the data as returned by WinHttpQueryDataAvailable is less than 300bytes.
b. The result from WinHttpReadData is true


What does your declaration of WinHttpReadData() actually look like? In particular, is the lpBuffer parameter declared as a Pointer or an untyped 'var'? It makes a big difference in how you pass your allocated buffer to it.

Dimitris wrote: I tried to change the winapi.winhttp and have the declaration from DELPHI 10.1 but even if I change it from notepad and Delphi IDE requests to reload it, the syntax is found incorrect during compile.


You should not make changes to Embarcadero's provided RTL units. You should not have to make such change to get your code working correctly. More likely, your own code is simply using the original declarations the wrong way.

Dimitris wrote: Where is the header file that it is used during compile?


Delphi doesn't use header files, only C++ does.
The following user(s) said Thank You: Dimitris

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
  • 2
Moderators: April Anne