This topic has not yet been rated - Rate this topic

InternetGetProxyInfo function

Applies to: desktop apps only

Retrieves proxy data for accessing specified resources. This function can only be called by dynamically linking to "JSProxy.dll". For better autoproxy support, use HTTP Services (WinHTTP) version 5.1 instead. For more information, see WinHTTP AutoProxy Support.

Syntax

BOOL InternetGetProxyInfo(
  __in   LPCSTR lpszUrl,
  __in   DWORD dwUrlLength,
  __in   LPSTR lpszUrlHostName,
  __in   DWORD dwUrlHostNameLength,
  __out  LPSTR *lplpszProxyHostName,
  __out  LPDWORD lpdwProxyHostNameLength
);

Parameters

lpszUrl [in]

A pointer to a null-terminated string that specifies the URL of the target HTTP resource.

dwUrlLength [in]

The size, in bytes, of the URL pointed to by lpszUrl.

lpszUrlHostName [in]

A pointer to a null-terminated string that specifies the host name of the target URL.

dwUrlHostNameLength [in]

The size, in bytes, of the host name pointed to by lpszUrlHostName.

lplpszProxyHostName [out]

A pointer to the address of a buffer that receives the URL of the proxy to use in an HTTP request for the specified resource. The application is responsible for freeing this string.

lpdwProxyHostNameLength [out]

A pointer to a variable that receives the size, in bytes, of the string returned in the lplpszProxyHostName buffer.

Return value

Returns TRUE if successful, or FALSE otherwise. To get extended error data, call GetLastError.

Remarks

To call InternetGetProxyInfo, you must dynamically link to it using the defined function-pointer type pfnInternetGetProxyInfo. The code snippet below shows how to declare an instance of this function-pointer type and then initialize and call it.


  HMODULE hModJS;                               // Handle for loading the DLL
  pfnInternetGetProxyInfo pIGPI;                // Function-pointer instance

  hModJS = LoadLibrary( TEXT("jsproxy.dll") );
  if (!hModJS)
  {
    _tprintf( TEXT("\nLoadLibrary failed to load jsproxy.dll with error: %d\n"),
            GetLastError( ) );
    return( FALSE );
  }

  pIGPI = (pfnInternetGetProxyInfo)
          GetProcAddress( hModJS, "InternetGetProxyInfo" );
  if (!pIGPI)         
  {
    _tprintf( TEXT("\nGetProcAddress failed to find InternetGetProxyInfo, error: %d\n"),
            GetLastError( ) );
    return( FALSE );
  }

  // The pIGPI function pointer can now be used to call InternetGetProxyInfo.



Like all other aspects of the WinINet API, this function cannot be safely called from within DllMain or the constructors and destructors of global objects.

Note  WinINet does not support server implementations. In addition, it should not be used from a service. For server implementations or services use Microsoft Windows HTTP Services (WinHTTP).

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

DLL

JSProxy.dll

See also

InternetInitializeAutoProxyDll
InternetDeInitializeAutoProxyDll
DetectAutoProxyUrl

 

 

Send comments about this topic to Microsoft

Build date: 2/7/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
How to free lplpszProxyHostName

To free the memory returned in lplpszProxyHostName, use GlobalFree().

InternetGetProxyInfo() Crashes
I was experiencing a crash every time I called InternetGetProxyInfo() and it turned out to be a threading problem.

I called IntenernetInitializeAutoProxyDll() with the PAC script just once on the main thread, and then InternetGetProxyInfo() in each thread that required it, but it crashed. I changed the code to just load the DLL on the main thread, and then Call IntenernetInitializeAutoProxyDll(), InternetGetProxyInfo() and IntenernetDeinitializeAutoProxyDll() on each thread and that did the trick... :-)

It seems that IntenernetInitializeAutoProxyDll() have something which make InternetGetProxyInfo() to be thread-dependant... ...weird. :-(
ERROR_CAN_NOT_COMPLETE

If this calls fails with ERROR_CAN_NOT_COMPLETE, it may be because you're calling it from a STA thread (see COM's threading models), so either call it from a non-COM thread or from a MTA thread.