IWebBrowser2 - get image data?

Just starting out? Need help? Post your questions and find answers here.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

IWebBrowser2 - get image data?

Post by Seymour Clufley »

Say the webgadget is displaying a webpage that contains this IMG tag:

Code: Select all

<IMG src="drawapicture.cgi">
That passes a request to a CGI program which returns image data. The browser then inserts that image data into the right place. If you refresh the page the request will be made again.

In the case of an image created dynamically by CGI/PHP, I don't know whether the browser saves the image data to a temporary file in the cache or if it just deals with it in memory.

Now say we use the IWebBrowser2 interface with the webgadget. We parse the HTML and find that image tag. I want to know if it's possible to get the image data (or the saved image file) and work with it. Specifically what I want to do is read it into memory and encode it to Base64, but the main problem is getting a handle to it in the first place.

I've done some preliminary googling and one guy suggests using FindFirstUrlCacheEntry and FindNextUrlCacheEntry.

Unfortunately there are no examples on the forum of using either of these functions. If anyone can demonstrate I'd be most grateful. API just isn't my strong point.

Thanks for reading,
Seymour.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Does anyone know a webpage where such an image request is made?! Unbelievably I can't find one. Google provides load of example source, but no working examples!

I can't do any testing without an example...
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

The webbrowser obtains the data similar (or using) to UrlDownloadToFile() API.
Anything get's in a inet tempfolder to be read for rendering.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

O btw.. 'such a request'?
It doesn't matter if you load a file directly from the webserver or streamed via a helper app like cgi.
As long the http headers provide the correct info and streams the data properly.
A webserver does the same.
See a CGI or ISAPI as a 'hook' in this case.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

I was thinking about authorisation, client ID etc.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

This little sample app uses FindFirstUrlCacheEntry_() and FindNextUrlCacheEntry_(). It's limited to 500 cache entries but you can see if it gets the info you are looking for.

http://www.heysparkie.com/Apps/read_cache.exe[/url]
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

http://www.heysparkie.com/ ....coming soon? :D
PureBasic for Windows
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

For the last 5 years and counting :oops:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Thanks Sparkie. I just tried out the program and it does list files in the IE cache.

Unfortunately I'm still searching for a webpage that has a dynamic image tag! I've asked on a webmasters' forum if anyone knows any examples - hopefully that will yield pages to work with. Until then I can't test out your program for the purpose at hand. Please bear with me.


In the meantime, I know that there are complications with accessing files in the cache. What I want to do is read a specific file in as data (to be Base64 encoded). Does anyone know any tricks for doing so?

Code in this thread uses an API command to delete a file in the cache:

Code: Select all

DeleteUrlCacheEntry_()
indicating that the normal PB command DeleteFile() wouldn't work. I'll do some testing...
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Does this page have what you're looking for?

http://www.muquit.com/muquit/software/C ... _5-ex.html
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4801
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Post by Fangbeast »

Sparkie wrote:For the last 5 years and counting :oops:

I keep going to http://www.heysparkie.com/ and it's so nice and soothing, no violent, eye searing content :):):):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Sparkie wrote:Does this page have what you're looking for?

http://www.muquit.com/muquit/software/C ... _5-ex.html
I found that page myself but on inspection I believe the images are pre-made examples.

I say that because the src for the images on it that I tested are all gif files (not cgi/exe/php or whatever) and the numbers don't change if you refresh.
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Sparkie, could you post the code for your program? I believe I've found a usable example!
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Here's the basic bare bones of the code...

Code: Select all

#ERROR_NO_MORE_ITEMS = 259 
#ERROR_INSUFFICIENT_BUFFER = 122 

Structure _INTERNET_CACHE_ENTRY_INFO 
  dwStructSize.l 
  lpszSourceUrlName.l 
  lpszLocalFileName.l 
  CacheEntryType.l 
  dwUseCount.l 
  dwHitRate.l 
  dwSizeLow.l 
  dwSizeHigh.l 
  LastModifiedTime.FILETIME 
  ExpireTime.FILETIME 
  LastAccessTime.FILETIME 
  LastSyncTime.FILETIME 
  lpHeaderInfo.l 
  dwHeaderInfoSize.l 
  lpszFileExtension.l 
  StructureUnion 
  dwReserved.l 
  dwExemptDelta.l 
  EndStructureUnion 
EndStructure 

requiredSize = 0 
; this call will come back with required buffer size contained in requiredSize 
hCache  = FindFirstUrlCacheEntry_(0, 0, @requiredSize) 
; allocate memory
*icInfo._INTERNET_CACHE_ENTRY_INFO = AllocateMemory(requiredSize) 
; this call will get the handle as well as the first entry 
hCache  = FindFirstUrlCacheEntry_(0, *icInfo, @requiredSize) 
Debug PeekS(*icInfo\lpszSourceUrlName)

; loop until lastError = #ERROR_NO_MORE_ITEMS 
; you'll also need to make sure buffer is big enough to hold the data 
; if not, allocate new memory space 
Repeat
  ;- to save time and cpu cycles, we'll count to 100 and stop
  ct + 1
  requiredSize = 0 
  result = FindNextUrlCacheEntry_(hCache, 0, @requiredSize) 
  FreeMemory(*icInfo) 
  *icInfo._INTERNET_CACHE_ENTRY_INFO = AllocateMemory(requiredSize) 
  result = FindNextUrlCacheEntry_(hCache, *icInfo, @requiredSize) 
  Debug PeekS(*icInfo\lpszSourceUrlName)
  lastError = getlasterror_()  
Until lastError = #ERROR_NO_MORE_ITEMS  Or ct = 100
If hCache
  FindCloseUrlCache_(hCache)
EndIf
FreeMemory(*icInfo)
Last edited by Sparkie on Tue Jan 13, 2009 3:38 am, edited 1 time in total.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Seymour Clufley
Addict
Addict
Posts: 1267
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Thanks, Sparkie. It seems to be work perfectly!

Do you think it would be wise to change the structure fields to integer type instead of longs?

And also, there might be a typo at the end:

Code: Select all

If cache
    FindCloseUrlCache_(hCache)
EndIf
Shouldn't it be "If hCache"?
Post Reply