I want to use HttpOpenRequest to download a file from internet using GET. I don't know how to declare the AcceptType parameter. The MS documentations says that it is an array of strings. So I declare it like this:
CONST
AcceptType: packed array[0..1] of LPWSTR = (PChar('*/*'), nil);
I have done something wrong? LPWSTR is a pointer to a string, however, the documentation says that I need a string. How do I declare a matrix of strings that are compatible with C++ ?
procedure THTTPGetThread.Execute;
CONST
AcceptType: packed array[0..1] of LPWSTR = (PChar('*/*'), nil); // Originally was: AcceptType:= PWideChar('Accept: ' + FTAcceptTypes);
VAR
hConnect: hInternet;
FileName: String;
Data: Array[0..1024] of Char;
TempStr: PAnsiChar;
RequestMethod: PChar;
InternetFlag: DWord;
begin
...
hRequest:= HttpOpenRequest(hConnect, RequestMethod, PChar(FileName), PChar('HTTP/1.0'), PChar(FTReferer), @AcceptType, InternetFlag, 0);
...
end;
I use Delphi XE. The MS documentation is here: http://msdn.microsoft.com/en-us/library/windows/desktop/aa384233(v=vs.85).aspx My function is multi-threaded so it won't block the program while it downloads. Single threaded functions won't work for me.
You are almost there. You just need to pass a pointer to the first element of the array:
@AcceptType[0]
In fact, as @Serg points out, this is equivalent to your existing code. So it seems that, as you have commented below, the issue you are facing is unrelated to the passing of this parameter.
As an aside, I think I would use PWideChar rather than LPWSTR, but that's not the issue here since they are equivalent.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With