Jump to content

Some help with DllStructCreate ( ) and DllCall()


Iczer
 Share

Go to solution Solved by Danyfirex,

Recommended Posts

I'm trying to get info from function http://msdn.microsoft.com/en-us/library/aa384185%28VS.85%29.aspx

BOOL GetUrlCacheEntryInfo(
  _In_     LPCTSTR lpszUrlName,
  _Out_    LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo,
  _Inout_  LPDWORD lpcbCacheEntryInfo
);

And have some troubles with "_INTERNET_CACHE_ENTRY_INFO" structure http://msdn.microsoft.com/en-us/library/aa385134%28v=vs.85%29.aspx

typedef struct _INTERNET_CACHE_ENTRY_INFO {
  DWORD    dwStructSize;
  LPTSTR   lpszSourceUrlName;
  LPTSTR   lpszLocalFileName;
  DWORD    CacheEntryType;
  DWORD    dwUseCount;
  DWORD    dwHitRate;
  DWORD    dwSizeLow;
  DWORD    dwSizeHigh;
  FILETIME LastModifiedTime;
  FILETIME ExpireTime;
  FILETIME LastAccessTime;
  FILETIME LastSyncTime;
  LPTSTR   lpHeaderInfo;
  DWORD    dwHeaderInfoSize;
  LPTSTR   lpszFileExtension;
  union {
    DWORD dwReserved;
    DWORD dwExemptDelta;
  };
} INTERNET_CACHE_ENTRY_INFO, *LPINTERNET_CACHE_ENTRY_INFO;

i make "union"  as "DWORD union". Is it right if i do not need info from it?

 

in "try1" case function return "1", and i get  $rezult[3] = 0 but "lpszLocalFileName = 0", "lpcbCacheEntryInfo = 0"

in "try2" case function return "0", and i get  $rezult[3] = 794 but"lpszLocalFileName = 0" and "lpcbCacheEntryInfo = 0"

What in my structure setup is not right ?

#include <Array.au3>

$tag_INTERNET_CACHE_ENTRY_INFO = "struct;DWORD dwStructSize; wstr lpszSourceUrlName; wstr lpszLocalFileName; DWORD CacheEntryType; DWORD dwUseCount; DWORD dwHitRate; DWORD dwSizeLow; DWORD dwSizeHigh; UINT64 LastModifiedTime; UINT64 ExpireTime; UINT64 LastAccessTime; UINT64 LastSyncTime; wstr lpHeaderInfo; DWORD dwHeaderInfoSize; wstr lpszFileExtension;  DWORD union;endstruct"
;$tag_INTERNET_CACHE_ENTRY_INFO = "struct;DWORD dwStructSize; LPTSTR lpszSourceUrlName; LPTSTR lpszLocalFileName; DWORD CacheEntryType; DWORD dwUseCount; DWORD dwHitRate; DWORD dwSizeLow; DWORD dwSizeHigh; FILETIME LastModifiedTime; FILETIME ExpireTime; FILETIME LastAccessTime; FILETIME LastSyncTime; LPTSTR lpHeaderInfo; DWORD dwHeaderInfoSize; LPTSTR lpszFileExtension; DWORD union;endstruct"
$struct_INTERNET_CACHE_ENTRY_INFO = DllStructCreate ( $tag_INTERNET_CACHE_ENTRY_INFO )
$ptr_INTERNET_CACHE_ENTRY_INFO = DllStructGetPtr ( $struct_INTERNET_CACHE_ENTRY_INFO )

$tag_lpcbCacheEntryInfo = "DWORD, lpcbCacheEntryInfo"
$struct_lpcbCacheEntryInfo = DllStructCreate ( $tag_lpcbCacheEntryInfo )
;DllStructSetData($struct_lpcbCacheEntryInfo,"lpcbCacheEntryInfo",0x0000ffff)
$ptr_lpcbCacheEntryInfo = DllStructGetPtr ( $struct_lpcbCacheEntryInfo )


$lpszUrlName = "http://www.autoitscript.com/autoit3/files/graphics/autoit_10_wall_1024x768.jpg"


ConsoleWrite("----------------------------------------------------------" &@crlf)
;----------------------------------------------------------------------------------------------
;try 1
;----------------------------------------------------------------------------------------------
$rezult = DllCall("Wininet.dll","BOOL","GetUrlCacheEntryInfoW","wstr",$lpszUrlName,"ptr",$ptr_INTERNET_CACHE_ENTRY_INFO,"ptr",$ptr_lpcbCacheEntryInfo)

_ArrayDisplay($rezult)
ConsoleWrite("$rezult = " & $rezult[0] &@crlf)

$lpszLocalFileName = DllStructGetData($struct_INTERNET_CACHE_ENTRY_INFO,"lpszLocalFileName")
ConsoleWrite("$lpszLocalFileName = " & $lpszLocalFileName &@crlf)

$lpcbCacheEntryInfo = DllStructGetData($struct_lpcbCacheEntryInfo,"lpcbCacheEntryInfo")
ConsoleWrite("$lpcbCacheEntryInfo = " & $lpcbCacheEntryInfo &@crlf)
ConsoleWrite("----------------------------------------------------------" &@crlf)
;----------------------------------------------------------------------------------------------
;try 2
;----------------------------------------------------------------------------------------------
$rezult = DllCall("Wininet.dll","BOOL","GetUrlCacheEntryInfoW","wstr",$lpszUrlName,"struct*",$ptr_INTERNET_CACHE_ENTRY_INFO,"dword*",$ptr_lpcbCacheEntryInfo)

_ArrayDisplay($rezult)
ConsoleWrite("$rezult = " & $rezult[0] &@crlf)

$lpszLocalFileName = DllStructGetData($struct_INTERNET_CACHE_ENTRY_INFO,"lpszLocalFileName")
ConsoleWrite("$lpszLocalFileName = " & $lpszLocalFileName &@crlf)

$lpcbCacheEntryInfo = DllStructGetData($struct_lpcbCacheEntryInfo,"lpcbCacheEntryInfo")
ConsoleWrite("$lpcbCacheEntryInfo = " & $lpcbCacheEntryInfo &@crlf)
;----------------------------------------------------------------------------------------------
ConsoleWrite("----------------------------------------------------------" &@crlf)
Edited by Iczer
Link to comment
Share on other sites

 

What in my structure setup is not right ?

$tag_lpcbCacheEntryInfo = "DWORD, lpcbCacheEntryInfo"
 

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

  • Solution

I think It could be something like this:

Global Const $hWinNet = DllOpen("wininet.dll")
Global Const $tagINTERNET_CACHE_ENTRY_INFO = "dword StructSize; ptr SourceUrlName; ptr LocalFileName; dword CacheEntryType; dword UseCount; dword HitRate; dword Size[2]; dword LastModifiedTime[2]; dword ExpireTime[2]; dword LastAccessTime[2]; dword LastSyncTime[2]; ptr HeaderInfo; dword HeaderInfoSize; ptr FileExtension; dword ReservedExemptDelta"

Local $sUrl= "http://www.autoitscript.com/autoit3/files/graphics/autoit_10_wall_1024x768.jpg"

Local $sLocalFileName = GetUrlCacheEntryInfo($sUrl)

msgbox(0,"",$sLocalFileName)

DllClose($hWinNet)

Func GetUrlCacheEntryInfo($Url)

    Local $tCacheEntryInfoSize = DllStructCreate("dword")


    DllCall($hWinNet, _
        "int", "GetUrlCacheEntryInfoW", _
            "wstr", $Url, _
            "ptr",       0, _
            "ptr",       DllStructGetPtr($tCacheEntryInfoSize))



    Local $tCacheEntryInfo = DllStructCreate( _
        $tagINTERNET_CACHE_ENTRY_INFO & "; " & _
        "byte[" & (DllStructGetData($tCacheEntryInfoSize, 1)+1) & "]")


    Local $avResult = DllCall($hWinNet, _
        "int", "GetUrlCacheEntryInfoW", _
            "wstr", $Url, _
            "ptr",       DllStructGetPtr($tCacheEntryInfo), _
            "ptr",       DllStructGetPtr($tCacheEntryInfoSize))

    $lPointer = DllStructGetData($tCacheEntryInfo, "LocalFileName")

    local $tLocalFileName=DllStructCreate("wchar[500]",$lPointer)
    Return DllStructGetData($tLocalFileName,1)

EndFunc

Saludos

 

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...