[twsocket] [OT] Problem migrating ProxyInfo to D2009

2009-02-17 Thread Maurizio Lotauro
Hi,

during the migration of my TProxyInfo component to D2009 I get a strange problem
that get me crazy. One API always fail with error 1003 (Cannot complete this
function). The exactly same code with D5 works (it show XYZT).
I explicitly declared Ansi what must be Ansi, so I really don't understand
what's wrong. 
If someone has an idea why it doesn't work, the follow is a sample code:


type
  PAutoProxyScriptBuffer = ^AUTO_PROXY_SCRIPT_BUFFER;
  AUTO_PROXY_SCRIPT_BUFFER = packed record
dwStructSize: DWORD;
lpszScriptBuffer: LPSTR;
dwScriptBufferSize: DWORD;
  end;
  TAutoProxyScriptBuffer = AUTO_PROXY_SCRIPT_BUFFER;

  TInitializeAutoProxyDll = function (
  dwVersion: DWORD;
  lpszDownloadedTempFile: LPSTR;
  lpszMime: LPSTR;
  lpAutoProxyCallbacks: Pointer;  //
AutoProxyHelperFunctions*
  lpAutoProxyScriptBuffer:
PAutoProxyScriptBuffer
 ): BOOL; stdcall;

  TGetProxyInfo = function (
lpszUrl: LPCSTR;
dwUrlLength: DWORD;
lpszUrlHostName: LPSTR;
dwUrlHostNameLength: DWORD;
out lplpszProxyHostName: LPSTR;
out lpdwProxyHostNameLength: DWORD
   ): BOOL; stdcall;

  TDeInitializeAutoProxyDll = function (
lpszMime: LPSTR;
dwReserved: DWORD
   ): BOOL; stdcall;

procedure TForm1.Button1Click(Sender: TObject);
var
  LibHandle: THandle;
  InitializeAutoProxyDll: TInitializeAutoProxyDll;
  GetProxyInfo: TGetProxyInfo;
  DeInitializeAutoProxyDll: TDeInitializeAutoProxyDll;
  ScriptText: AnsiString;
  ScriptBuffer: TAutoProxyScriptBuffer;
  Url: AnsiString;
  Host: AnsiString;
  ProxyName: PAnsiChar;
  ProxyLength: LongWord;
begin
  LibHandle := SafeLoadLibrary('jsproxy.dll');
  if LibHandle = 0 then
Exit;

  try
@InitializeAutoProxyDll := GetProcAddress(LibHandle,
'InternetInitializeAutoProxyDll');
if @InitializeAutoProxyDll = nil then
begin
  ShowMessageFmt('GetProcAddress(''InternetInitializeAutoProxyDll'') failed:
error %d (%s)', [GetLastError, SysErrorMessage(GetLastError)]);
  Exit;
end;

@GetProxyInfo := GetProcAddress(LibHandle, 'InternetGetProxyInfo');
if @GetProxyInfo = nil then
begin
  ShowMessageFmt('GetProcAddress(''InternetGetProxyInfo'') failed: error %d
(%s)', [GetLastError, SysErrorMessage(GetLastError)]);
  Exit;
end;

@DeInitializeAutoProxyDll := GetProcAddress(LibHandle,
'InternetDeInitializeAutoProxyDll');
if @DeInitializeAutoProxyDll = nil then
begin
  ShowMessageFmt('GetProcAddress(''InternetDeInitializeAutoProxyDll'')
failed: error %d (%s)', [GetLastError, SysErrorMessage(GetLastError)]);
  Exit;
end;

ScriptText := 'function FindProxyForURL(url, host)'#13#10'{'#13#10'return
XYZT;'#13#10'}'#13#10;
ScriptBuffer.dwStructSize := SizeOf(TAutoProxyScriptBuffer);
ScriptBuffer.lpszScriptBuffer := PAnsiChar(ScriptText);
ScriptBuffer.dwScriptBufferSize := Length(ScriptText) + 1;
if not InitializeAutoProxyDll(0, nil, nil, nil, @ScriptBuffer) then
begin
  ShowMessageFmt('InternetInitializeAutoProxyDll() failed: error %d (%s)',
[GetLastError, SysErrorMessage(GetLastError)]);
  Exit;
end;

try
  Url := 'URL';
  Host := 'host';
  ProxyName := nil;
  try
if not GetProxyInfo(PAnsiChar(Url), Length(Url) + 1, PAnsiChar(Host),
Length(Host) + 1, ProxyName, ProxyLength) then
begin
  ShowMessageFmt('InternetGetProxyInfo() failed: error %d (%s)',
[GetLastError, SysErrorMessage(GetLastError)]);
  Exit;
end;
ShowMessage(ProxyName);
  finally
if ProxyName  nil then
  GlobalFree(HGLOBAL(ProxyName));
  end;
finally
  if not DeInitializeAutoProxyDll(nil, 0) then
ShowMessageFmt('InternetDeInitializeAutoProxyDll() failed: error %d
(%s)', [GetLastError, SysErrorMessage(GetLastError)]);
end;
  finally
FreeLibrary(LibHandle);
  end;
end;


Bye, Maurizio.


This mail has been sent using Alpikom webmail system
http://www.alpikom.it

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009

2009-02-17 Thread Arno Garrels
Hi Maurizio,

 One API always fail with error 1003 

Which one? Which line?

From a very brief look:

 TGetProxyInfo = function (
lpszUrl: LPCSTR;

LPCSTR maps to either Ansi or Unicode, however you pass it a PAnsiChar
URL?

--
Arno Garrels



-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009

2009-02-17 Thread Maurizio Lotauro
Scrive Arno Garrels arno.garr...@gmx.de:

 Hi Maurizio,

Hi Arno,

  One API always fail with error 1003 
 
 Which one? Which line?

When the GetProxyInfo is called.
You can try yourself, the code that I posted practically works out of the box.

 From a very brief look:
 
  TGetProxyInfo = function (
 lpszUrl: LPCSTR;
 
 LPCSTR maps to either Ansi or Unicode, however you pass it a PAnsiChar
 URL?

No, LPCSTR maps only to PAnsiChar. The type you are referring is LPCTSTR.


Bye, Maurizio.


This mail has been sent using Alpikom webmail system
http://www.alpikom.it

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009

2009-02-17 Thread Arno Garrels
Maurizio Lotauro wrote:
 Scrive Arno Garrels arno.garr...@gmx.de:
 
 Hi Maurizio,
 
 Hi Arno,
 
 One API always fail with error 1003
 
 Which one? Which line?
 
 When the GetProxyInfo is called.
 You can try yourself, the code that I posted practically works out of
 the box. 

What is TInitializeAutoProxyDll?

 
 From a very brief look:
 
 TGetProxyInfo = function (
 lpszUrl: LPCSTR;
 
 LPCSTR maps to either Ansi or Unicode, however you pass it a
 PAnsiChar URL?
 
 No, LPCSTR maps only to PAnsiChar. The type you are referring is
 LPCTSTR. 

Arrgh, mixed up the types :)

--
Arno Garrels 

 
 
 Bye, Maurizio.
 
 
 This mail has been sent using Alpikom webmail system
 http://www.alpikom.it
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009

2009-02-17 Thread Arno Garrels
Arno Garrels wrote:
 
 What is TInitializeAutoProxyDll?

Sorry, found, I should stop coding today :)

--
Arno Garrels


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009

2009-02-17 Thread Matt Minnis
Yeah, we all have days like that.
On those days, you'll save yourself time by doing something else. 

-Original Message-
From: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] On
Behalf Of Arno Garrels
Sent: Tuesday, February 17, 2009 13:20
To: ICS support mailing
Subject: Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009

Arno Garrels wrote:
 
 What is TInitializeAutoProxyDll?

Sorry, found, I should stop coding today :)

--
Arno Garrels


-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009

2009-02-17 Thread Arno Garrels
Matt Minnis wrote:
 Yeah, we all have days like that.
 On those days, you'll save yourself time by doing something else.

Thanks, that's helpful, I'll try to continue investigating deeper 
reasons of the financial crisis today, very interesting stuff, btw! But 
unfortunately rather OT. 
  
--
Arno Garrels 

 

 
 -Original Message-
 From: twsocket-boun...@elists.org
 [mailto:twsocket-boun...@elists.org] On Behalf Of Arno Garrels
 Sent: Tuesday, February 17, 2009 13:20
 To: ICS support mailing
 Subject: Re: [twsocket] [OT] Problem migrating ProxyInfo to D2009
 
 Arno Garrels wrote:
 
 What is TInitializeAutoProxyDll?
 
 Sorry, found, I should stop coding today :)
 
 --
 Arno Garrels
 
 
 --
 To unsubscribe or change your settings for TWSocket mailing list
 please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
 Visit our website at http://www.overbyte.be
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be