Page 1 of 2

IWebBrowser2 - get image data?

Posted: Sun Jan 11, 2009 8:28 am
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.

Posted: Sun Jan 11, 2009 10:10 am
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...

Posted: Sun Jan 11, 2009 2:44 pm
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.

Posted: Sun Jan 11, 2009 2:46 pm
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.

Posted: Sun Jan 11, 2009 4:39 pm
by Seymour Clufley
I was thinking about authorisation, client ID etc.

Posted: Sun Jan 11, 2009 10:11 pm
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]

Posted: Sun Jan 11, 2009 10:17 pm
by Marco2007
http://www.heysparkie.com/ ....coming soon? :D

Posted: Sun Jan 11, 2009 10:23 pm
by Sparkie
For the last 5 years and counting :oops:

Posted: Mon Jan 12, 2009 3:38 am
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...

Posted: Mon Jan 12, 2009 3:59 am
by Sparkie
Does this page have what you're looking for?

http://www.muquit.com/muquit/software/C ... _5-ex.html

Posted: Mon Jan 12, 2009 5:16 am
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 :):):):)

Posted: Mon Jan 12, 2009 5:32 am
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.

Posted: Mon Jan 12, 2009 12:41 pm
by Seymour Clufley
Sparkie, could you post the code for your program? I believe I've found a usable example!

Posted: Mon Jan 12, 2009 3:54 pm
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)

Posted: Mon Jan 12, 2009 5:43 pm
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"?