Click here to Skip to main content
15,896,359 members

Problem compiling/linking WinHTTP example

Rezame asked:

Open original thread
Hi,
i am trying using below code for connect to server but there are some errors.
Can anybody help me?
C++
/************************************************************
*                                                           *
* RetOptions.cpp                                            *
*                                                           *
* Copyright (c) Microsoft Corporation. All Rights Reserved. *
*                                                           *
************************************************************/

#include #windows.h#
#include #winhttp.h#;
#include #stdio.h#


int main(int argc, char* argv[])
{
    HINTERNET hSession;
    HINTERNET hConnect;
    HINTERNET hRequest;
    BOOL httpResult;
    DWORD data;
    DWORD dwSize = sizeof(DWORD);
    LPWSTR pwszURL;


    // Print a description of the sample.
    printf("This sample demonstrates the process for retrieving WinHTTP\n");
    printf("options programmatically from a C/C++ application. WinHTTP\n");
    printf("application programming interface (API) functions are used to\n");
    printf("determine the default connect time-out value and to find the\n");
    printf("current URL after an HTTP request is redirected.\n\n");

    // Use WinHttpOpen to obtain a session handle.
    hSession = WinHttpOpen(  L"A WinHTTP Example Program/1.0", 
                             WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
                             WINHTTP_NO_PROXY_NAME, 
                             WINHTTP_NO_PROXY_BYPASS, 0);

    // Use WinHttpQueryOption to retrieve Internet options.
    httpResult = WinHttpQueryOption( hSession, WINHTTP_OPTION_CONNECT_TIMEOUT, 
                                     &data, &dwSize);
    if (httpResult) 
        printf("Connect time-out:\t%u ms\n",data);

    // Use WinHttpConnect to specify an HTTP server.
    hConnect = WinHttpConnect( hSession, L"msdn.microsoft.com",
                               INTERNET_DEFAULT_HTTP_PORT, 0);

    // Open and Send a Request Header.
    hRequest = WinHttpOpenRequest( hConnect, L"GET", 
                         L"/downloads/samples/internet/winhttp/retoptions/redirect.asp", 
                         NULL, WINHTTP_NO_REFERER, 
                         WINHTTP_DEFAULT_ACCEPT_TYPES, 0);                     
    httpResult = WinHttpSendRequest( hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 
                                     0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
    httpResult = WinHttpReceiveResponse( hRequest, NULL);

    // Use WinHttpQueryOption again, this time to obtain a buffer size.
    httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL, 
                                     NULL, &dwSize);
    pwszURL = new WCHAR[dwSize/sizeof(WCHAR)];
    
    // Use WinHttpQueryOption to retrieve Internet options.
    httpResult = WinHttpQueryOption( hRequest, WINHTTP_OPTION_URL, 
                                     (void *)pwszURL, &dwSize);
    printf("Redirected URL:\t\t%S\n",pwszURL);

    // Free the allocated memory.
    delete [] pwszURL;

    // When finished, release the hRequest handle.
    httpResult = WinHttpCloseHandle(hRequest);
    if (!httpResult)
        printf("Could not close the hRequest handle.\n");

    // When finished, release the hConnect handle.
    httpResult = WinHttpCloseHandle(hConnect);
    if (!httpResult)
        printf("Could not close the hConnect handle.\n");

    // When finished, release the hSession handle.
    httpResult = WinHttpCloseHandle(hSession);
    if (!httpResult)
        printf("Could not close the hSession handle.\n");


    return 0;
}


my error is as below:

1>------ Build started: Project: 111, Configuration: Debug Win32 ------
1>Compiling...
1>111.cpp
1>Linking...
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpCrackUrl@16 referenced in function _wmain
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpCloseHandle@4 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpQueryHeaders@24 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpReceiveResponse@8 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpWriteData@16 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpSendRequest@28 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpAddRequestHeaders@16 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpenRequest@28 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpConnect@16 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>111.obj : error LNK2019: unresolved external symbol __imp__WinHttpOpen@20 referenced in function "int __cdecl WinHttpFormSubmitSample(wchar_t const *,unsigned short,wchar_t *,int,wchar_t *)" (?WinHttpFormSubmitSample@@YAHPB_WGPA_WH1@Z)
1>C:\Users\Reza\Desktop\111\Debug\111.exe : fatal error LNK1120: 10 unresolved externals
1>Build log was saved at "file://c:\Users\Reza\Desktop\111\111\Debug\BuildLog.htm"
1>111 - 11 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Best Regards,
Tags: C++, Networking

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900