Any guesses as to why this simple test code would show WinHttpConnect fails with error code 6 (invalid handle or ERROR_INVALID_HANDLE):
HINTERNET internet = WinHttpOpen(L"test",WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_NO_PROXY_NAME,WINHTTP_NO_PROXY_BYPASS,0);
assert(internet == (HINTERNET)1);
HINTERNET connect = WinHttpConnect(internet,L"www.microsoft.com",INTERNET_DEFAULT_HTTP_PORT,0);
assert(!connect);
DWORD err = GetLastError();
assert(err == 6);
All of the above asserts pass. I've run this code on my Win8 PC and also on a Win2003 server. Two different PCs, same issue. My original code was more complex and runs as a service, but I reduced down to this code and just ran it in a simple test app in user mode (not service).
My app is compiled with an older compiler, Borland Builder 6, but not sure that should be a problem.