【发布时间】:2013-12-25 15:22:44
【问题描述】:
我将 Internet Explorer 配置为使用本地 PAC 文件:
它工作得很好。但是当我尝试调用InternetGetProxyInfo() 时,它会以ERROR_CAN_NOT_COMPLETE 失败。可能是什么问题?
#ifndef WINVER // Allow use of features specific to Windows XP or later.
#define WINVER 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <winsock2.h>
#include <windows.h>
#include <wininet.h>
#include <tchar.h>
#define URL "http://www.yandex.ru/"
#define HOST "www.yandex.ru"
int _tmain(int argc, _TCHAR* argv[])
{
char proxyBuffer[1024];
char *str = proxyBuffer;
DWORD nb = 1024;
DWORD dw;
BOOL b;
pfnInternetGetProxyInfo pIGPI; // Function-pointer instance
/* code from MSDN: */
{
HMODULE hModJS; // Handle for loading the DLL
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.
}
InternetInitializeAutoProxyDll(0); /* wininet.dll version of this function */
SetLastError(0);
b = pIGPI(URL,sizeof(URL),HOST,sizeof(HOST), &str, &nb);
dw = GetLastError();
SetLastError(0);
b = pIGPI(URL,sizeof(URL)-1,HOST,sizeof(HOST)-1, &str, &nb);
dw = GetLastError();
return 0;
}
请不要告诉我使用其他 API,这是一个教育问题,而不是实际问题。
【问题讨论】:
-
@sftrabbit 是的“第一次”。如您所见,我两次调用 pIGPI()。
-
我发现
wininet.dll中的InternetInitializeAutoProxyDll()只是一个存根。 -
但是
wininet.dll知道如何使用正确的参数在jsproxy.dll中调用InternetInitializeAutoProxyDll()