Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74765

Is there something wrong with the datatypes I'm using ? (Argument of const char* is not compatible with parameter of type LPCSTR)

$
0
0

I am trying to extract the links from a given webpage using the urlmon library for a class project. I have attached an image to show the error. The error says: "C++ argument of type "const char*"is incompatible with parameter of type "LPCSTR." Any clues on what I did incorrectly?

Using Visual Studio 2019

I am a relatively new programmer, so please explain thoroughly and in a simple/comprehensible manner.

#include <windows.h>
#include <fstream>
#include <iostream>
#include <set>
#include <regex>
using namespace std;

typedef HRESULT(WINAPI* UDTF)(LPVOID, LPCTSTR, LPCTSTR, DWORD, LPVOID);

bool getURLToFile(string url, string file)
{
    int r = 1;
    HMODULE hDll;
    UDTF URLDownloadToFile;

    if ((hDll = LoadLibrary(LPCWSTR("urlmon")))) // Loads the module (DLL) urlmon into this process
    {
        if ((URLDownloadToFile = (UDTF)GetProcAddress(hDll, "URLDownloadToFileA"))) // Retrieves the function URLDownloadToFileA from the urlmon DLL
        {
            if (URLDownloadToFile(NULL, url.c_str(), file.c_str(), 0, 0) == 0) // Actual download happens here
            {
                r = 0; // Success!
            }
        }
        FreeLibrary(hDll); // Unload the module
    }
    return !r; // return True if r = 0
}

string getStringFromFile(string file_name)
{
    ifstream file(file_name); // Creates the file stream
    return { istreambuf_iterator<char>(file), istreambuf_iterator<char>{} };
}

set<string> extractLinks(string file_name)
{
    static const regex href_regex("<a href=\"(.*?)\"", regex_constants::icase); // Creates the regex that parses <a> tags

    const string text = getStringFromFile(file_name); // Gets stored string

    return { sregex_token_iterator(text.begin(), text.end(), href_regex, 1), sregex_token_iterator{} }; // Returns the set of matched instances
}

int main(void)
{
    string url;
    string file = "sample.txt"; // File for temporary storage of web page
    cout << "Please enter a url address: ";
    cin >> url;

    if (getURLToFile(url, file)) // Try to get the url
    {
        cout << "The following links were found:"<< endl;
        for (string ref : extractLinks(file)) // Print all the links in the set
        {
            cout << ref << endl;
        }
        cout << "Done!"<< endl;
    }
    else
    {
        cout << "Could not fetch the url"<< endl;
    }

}

image


Viewing all articles
Browse latest Browse all 74765

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>