1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
#undef UNICODE
#include <windows.h>
#include <WinInet.h>
#define EXPORT extern "C" __declspec(dllexport)
EXPORT void RequestFunc()
{
/*
HINTERNET hInternetOpen = InternetOpen("HTTPGET", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
HINTERNET hInternetConnect = InternetConnect(hInternetOpen, "www.rottentomatoes.com", INTERNET_DEFAULT_HTTP_PORT,NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
HINTERNET m_hRequest = HttpOpenRequest(hInternetConnect,"GET","/index.jsp","HTTP/1.1",NULL, NULL,INTERNET_FLAG_RELOAD | INTERNET_FLAG_EXISTING_CONNECT, 0);
*/
MessageBoxA(0, "William", "Krauss", 0);
// for clarity, error-checking has been removed
HINTERNET hSession = InternetOpen("MyAgent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, "www.google.com", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "/test.txt", NULL, NULL, 0, 0, 1);
HttpSendRequest(hRequest, 0, 0, 0, 0);
// close any valid internet-handles
InternetCloseHandle(hSession);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
/*
InternetCloseHandle(hInternetOpen);
InternetCloseHandle(hInternetConnect);
InternetCloseHandle(m_hRequest);
*/
}
DWORD WINAPI RequestThread() {
// for clarity, error-checking has been removed
HINTERNET hSession = InternetOpen("MyAgent", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, "www.google.com", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "/test.txt", NULL, NULL, 0, 0, 1);
MessageBox(NULL, "TEST", "TEST", MB_OK);
if (!HttpSendRequestA(hRequest, 0, 0, 0, 0)) {
MessageBox(NULL, "FAIL", "FAIL", MB_OK);
}
else {
MessageBox(NULL, "ALL OK", "OK", MB_OK);
}
// close any valid internet-handles
InternetCloseHandle(hSession);
InternetCloseHandle(hConnect);
InternetCloseHandle(hRequest);
return 0;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
CreateRemoteThread(NULL, NULL, RequestThread(), NULL, NULL, NULL, NULL);
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
|