3

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.

1
  • 1
    There is nothing wrong in a way you pass AcceptType Commented Oct 11, 2011 at 12:04

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I have tried that but my program still has problems. More exactly the program cannot be shutdown WHEN I use that function to download a file. So I will try to find my problem somewhere else. Thanks anyway! +1
Yes David. I never said that it is otherwise.
this is a surprising element of delphi pointer/address syntax, for some C programmers. I remember when I found it surprising. I'm so used to it now, that I've forgotten to be surprised anymore.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.