Remove Image From Memory.

Hii Guys!!

I am making a program that retrieves a download link from a website, and with the retrieved data, will then download a PNG image file (Local Webserver).

Now, if I was to replace the image (On The Webserver) with another image, when the program attempts to download the image it always retrieves the original image as though it is cached on my PC somewhere.

I hope that I explained myself clear enough for people to understand!

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
#include<iostream>
#include<Windows.h>
#include<wininet.h>
#include<cstring>
#include <tchar.h>
#include <urlmon.h>

#pragma comment(lib,"wininet.lib")
#pragma comment(lib, "urlmon.lib")

using namespace std;

char DataReceived[4096];

void Stealth()
{
	HWND Stealth;
	AllocConsole();
	Stealth = FindWindowA("ConsoleWindowClass", NULL);
	ShowWindow(Stealth, 0);
}

int main() {
	Stealth();

	HINTERNET connect = InternetOpen("MyBrowser", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);

	if (!connect) {
		cout << "Connection Failed or Syntax error";
		return 0;
	}

	HINTERNET OpenAddress = InternetOpenUrl(connect, "http://tester.atwebpages.com/tempaddy.txt", NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION, 0);

	if (!OpenAddress)
	{
		DWORD ErrorNum = GetLastError();
		cout << "Failed to open URL \nError No: " << ErrorNum;
		InternetCloseHandle(connect);
		return 0;
	}

	DWORD NumberOfBytesRead = 0;
	while (InternetReadFile(OpenAddress, DataReceived, 4096, &NumberOfBytesRead) && NumberOfBytesRead)
	{
		 URLDownloadToFile(NULL, DataReceived, "c:\\windows\\temp\\temp.png", BINDF_GETNEWESTVERSION, NULL);
	}

	InternetCloseHandle(OpenAddress);
	InternetCloseHandle(connect);
	return 0;
}


The retrieved data from the website is "http://192.168.1.118/1.png".
If I was to change the image file to another (same filename), the result will be the same as when the image was first downloaded and I cannot get it to download the fresh image with the same filename.

Many Thanks For All Help!!

Googie.


EDIT: Even if I disable the web server it will still say that it downloaded the image (cached).
Last edited on
> it always retrieves the original image as though it is cached on my PC somewhere.

By default, it is cached on the local hard disk.
See: https://docs.microsoft.com/en-us/windows/win32/wininet/caching

You could use the flag INTERNET_FLAG_PRAGMA_NOCACHE with InternetOpenUrl
https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-internetopenurla

or call DeleteUrlCacheEntry
https://docs.microsoft.com/en-us/windows/win32/api/wininet/nf-wininet-deleteurlcacheentry
Topic archived. No new replies allowed.