2

The Background:


I'm trying to write a windows program to serve as a client-side HTML viewer. Since the development IDE that I'm using (Code::Blocks v:13.12) doesn't come with a copy of winHTTP.lib, I had to download a copy of the Windows 10 SDK.

I then proceeded to write the following code:

#include <iostream>
#include <windows.h>
#include <...\Windows Kits\10\Include\10.0.10586.0\um\winhttp.h>

const LPCWSTR Agent = (wchar_t*)TEXT("User Agent");
const LPCWSTR Url = (wchar_t*)TEXT("www.google.com");

using namespace std;

int main()
{
    // Declare Variables:
    DWORD dwSize = 0;
    DWORD dwDownloaded = 0;
    LPSTR pszOutBuffer;
    BOOL  bResults = FALSE;
    HINTERNET hSession = NULL,
              hConnect = NULL,
              hRequest = NULL;

    // Use WinHttpOpen to obtain a session handle:
    hSession = WinHttpOpen(Agent,
                          WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                          WINHTTP_NO_PROXY_NAME,
                          WINHTTP_NO_PROXY_BYPASS, 0 );

    // Specify an HTTP server.
    if( hSession )
        hConnect = WinHttpConnect( hSession, Url, INTERNET_DEFAULT_HTTPS_PORT, 0 );

    // Create an HTTP request handle.
    if( hConnect )
        hRequest = WinHttpOpenRequest(hConnect, L"GET", NULL,
                                        NULL, WINHTTP_NO_REFERER,
                                        WINHTTP_DEFAULT_ACCEPT_TYPES,
                                        WINHTTP_FLAG_SECURE );

    /*
     * <INCOMPLETE>
     */

    // Terminate Process Successfully:
    return EXIT_SUCCESS;
}

(Note: "...\Windows Kits\" is the path to my copy of the Windows SDK)

I then proceeded to link my program to the "winHTTP.lib" library.


The Problem:


Now, every time I try to compile my program, I get the following result:

In "...\Windows Kits\10\Include\10.0.10586.0\um\winhttp.h": fatal error: winapifamily.h: No such file or directory

It seems that for whatever reason, my compiler is unable to find this "winapifamily.h".


The Questions:


  1. Is this a problem with the compiler, the Windows SDK, or have I made an error in my code?

  2. How can I fix this? Do I need to install another copy of the winHTTP Library, or is there a more simple way for me to solve the problem?



Forgot To Mention:


I suspect that this might be a problem with the search path for my IDE not lining up with the Windows 10 SDK. Is this a reasonable conclusion to draw?
  • 1
    Is `winapifamily.h` where it should be? check... also, the library you linked may require you to include header files. – Evan Carslake Feb 21 '16 at 01:48
  • It's hard to say; I don't really know where it should be. –  Feb 21 '16 at 01:50
  • Search on your computer `"winapifamily.h"` and see your results. – Evan Carslake Feb 21 '16 at 01:53
  • Found it: it's path was "...\Windows Kits\10\Include\10.0.10586.0\shared" –  Feb 21 '16 at 01:57
  • that looks slightly different than the path you are using. – Evan Carslake Feb 21 '16 at 02:04
  • So, how should I fix this path issue? Is it an IDE-specific solution? –  Feb 21 '16 at 02:08
  • for the visible IDE yesish. The problem presents itself with the makefile. On a side note: `<...\Windows Kits\10\Include\10.0.10586.0\um\winhttp.h>` is more than surely incorrect. – Evan Carslake Feb 21 '16 at 02:11
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/104075/discussion-between-chef-cyanide-and-evan-carslake). –  Feb 21 '16 at 02:14
  • 1
    As far I know CodeBlocks doesn't come with any windows library. Maybe you are using MinGW or something, which doesn't support winHTTP but it does have support for WinInet. Most of the time WinInet is a better choice anyway. You might also look at using IE based Web browser control. – Barmak Shemirani Feb 21 '16 at 02:15
  • @BarmakShemirani WinInet huh? I'll look into it. –  Feb 21 '16 at 02:16

0 Answers0