I'm trying to get a request from a DLL (which is hooked into a program) but no matter what I try, everything just hangs.
I tried to use CURL and WinHttpClient. Both did the same thing but slightly differently.
CURL made the program hang for a long time and then displayed nothing (that code isn't commented and contains code from other Stack Overflow questions.)
WinHttpClient immediately returns nothing.
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
//#include "WinHttpClient/WinHttpClient.h"
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <curl/curl.h>
using namespace std; // fix later
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
extern "C" __declspec(dllexport) void Quack();
__declspec(dllexport) void Quack() {
/*WinHttpClient client(L"http://www.google.com");
client.SetUserAgent(L"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1;...)");
client.SendHttpRequest();
wstring httpResponseHeader = client.GetResponseHeader();
wstring httpResponseContent = client.GetResponseContent();
std::string thingstr((const char*)&httpResponseContent[0], sizeof(wchar_t) / sizeof(char)*httpResponseContent.size());
LPCSTR thing = (LPCSTR)httpResponseContent.c_str();
MessageBoxA(NULL, thing, "Quack", MB_OK);*/
CURL *curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
MessageBoxA(NULL, (LPCSTR)readBuffer.c_str(), "Quack", MB_OK);
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
Quack();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Does anyone have a solution? Any answer or suggestion is appreciated.