473,320 Members | 1,900 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Getting FindFirstUrlCacheEntry to work?

Hello -

I am desperately trying to get the FindFirstUrlCacheEntry() function to
work under VB.NET. Unfortunately all I can find when I do a Google are
examples for older VB versions. The "As Any" does not work any more
and there are lots of other problems.

Could anybody tell me how to implement FindFirstUrlCacheEntry in
VB.NET?

Here is what I tried ...

Public Structure FILETIME
Dim dwLowDateTime As Long
Dim dwHighDateTime As Long
End Structure

Public Structure INTERNET_CACHE_ENTRY_INFO
Dim dwStructSize As Long
Dim lpszSourceUrlName As Long
Dim lpszLocalFileName As Long
Dim CacheEntryType As Long 'String
Dim dwUseCount As Long
Dim dwHitRate As Long
Dim dwSizeLow As Long
Dim dwSizeHigh As Long
Dim LastModifiedTime As FILETIME
Dim ExpireTIme As FILETIME
Dim LastAccessTime As FILETIME
Dim LastSyncTime As FILETIME
Dim lpHeaderInfo As Long
Dim dwHeaderInfoSize As Long
Dim lpszFileExtension As Long 'String
Dim dwReserved As Long
End Structure

Public Declare Function FindFirstUrlCacheEntry Lib "wininet" _
Alias "FindFirstUrlCacheEntryA" _
(ByVal lpszUrlSearchPattern As String, _
ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long

....

Dim hFile As Long
Dim lData As INTERNET_CACHE_ENTRY_INFO

hFile = FindFirstUrlCacheEntry("http://msdn.microsoft.com/", lData ,
lBuffer)

This at least does not crash but I do not get any useful data out of
it. The problem must be that some of member variables (e.g.
lpszSourceUrlName) are actually pointers to strings.

How can I convert the Long to a String ... or rather how can I copy the
memory the Long points to into a String?

Thanks for any hints!

Joe

Nov 21 '05 #1
2 4543
Joe,

The first and the main problem of your code is misuse of Long type.
Remember that "Classic" VB's Long corresponds to .NET System.Int32 or VB
..NET Integer. Thus, you have to replace Longs with Integers.

Second, FILETIME is already declared in System.Runtime.InteropServices
namespace, so you must not declare it yourself.

Third, FindFirstUrlCacheEntry() requires to be called specially. Look at the
example:

~
Imports System.Runtime.InteropServices

....

Private Declare Ansi Function FindFirstUrlCacheEntryA Lib "wininet.dll" ( _
<MarshalAs(UnmanagedType.LPStr), [In]()> ByVal lpszUrlSearchPattern As
String, _
ByVal lpFirstCacheEntryInfo As IntPtr, _
ByRef lpdwFirstCacheEntryInfoBufferSize As Int32 _
) As IntPtr

<StructLayout(LayoutKind.Sequential)> Private Structure
INTERNET_CACHE_ENTRY_INFOA
Public dwStructSize As Integer
<MarshalAs(UnmanagedType.LPStr)> Public lpszSourceUrlName As String
<MarshalAs(UnmanagedType.LPStr)> Public lpszLocalFileName As String
Public CacheEntryType As Integer
Public dwUseCount As Integer
Public dwHitRate As Integer
Public dwSizeLow As Integer
Public dwSizeHigh As Integer
Public LastModifiedTime As FILETIME
Public ExpireTime As FILETIME
Public LastAccessTime As FILETIME
Public LastSyncTime As FILETIME
Public lpHeaderInfo As IntPtr
Public dwHeaderInfoSize As Integer
<MarshalAs(UnmanagedType.LPStr)> Public lpszFileExtension As String
Public dwExemptDelta As Integer
End Structure

....

Dim fcei As INTERNET_CACHE_ENTRY_INFOA, fceibs As Integer
FindFirstUrlCacheEntryA(Nothing, IntPtr.Zero, fceibs) REM determine amount
of memory needed
Dim AllocatedSpace As IntPtr = Marshal.AllocHGlobal(fceibs) REM allocate
memory
Dim hFile As IntPtr = FindFirstUrlCacheEntryA("*.*", AllocatedSpace, fceibs)
fcei = CType(Marshal.PtrToStructure(AllocatedSpace, fcei.GetType),
INTERNET_CACHE_ENTRY_INFOA) REM get info
Marshal.FreeHGlobal(AllocatedSpace) REM free memory
~
How can I convert the Long to a String ... or rather how can I copy the
memory the Long points to into a String?


Again Integer, not Long...
Take a look at System.Runtime.InteropServices.Marshal.PtrToString * methods.

I hope it helps.

Roman
Nov 21 '05 #2
Hello Roman -

Works great ... thanks so much for you help!

Joe

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
3
by: James | last post by:
Please help - getting very desperate! Sun, 12 October 2003 05:39 I have PHPDEV 4.2.3 from Firepages.com.au as the upgrade to 4.3.0 did not work. I also had an abortive download from PHP.NET as...
7
by: Chris | last post by:
<apologies for cross-posting> Hi All, I am based in the UK and have been doing some private work for a client which involved setting up a database and scripts to search it and display results...
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
5
by: Brian Henry | last post by:
I have a page which reads an article from the database it has 1 text box, 2 dropdown lists, and a longreat HTML text box. I load the information from the database when the page is set to edit mode...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
12
by: ekareem | last post by:
Hi, I am so overwhelmed with how much is out there in ASP.NET 2.0 - Even if you are OK with a core language like VB or C# and database topics, you still got to climb the mountain of Web Design,...
12
by: Premal | last post by:
Hi, I tried to make delete operator private for my class. Strangely it is giving me error if I compile that code in VC++.NET. But it compiles successfully on VC++6.o. Can anybody give me inputs...
7
by: alphasahoo | last post by:
Hi I am working on a program which writes the output a SQL select statements from number of source tables first to a load matrix and then writes to a load.dat file. But while writing to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.