Jump to content

Create pointer to strings and ints in dllcall


martin
 Share

Recommended Posts

I want to use wininet to get the information on the last error but I don't know how to format the parameters for the pointers.

The function I want to use is this -

BOOL InternetGetLastResponseInfo(

LPDWORD lpdwError,

LPTSTR lpszBuffer,

LPDWORD lpdwBufferLength

);

Parameters

lpdwError

[out] Pointer to a variable that receives an error message pertaining to the operation that failed.

lpszBuffer

[out] Pointer to a buffer that receives the error text.

lpdwBufferLength

[in, out] Pointer to a variable that contains the size of the lpszBuffer buffer, in TCHARs. When the function returns, this parameter contains the size of the string written to the buffer, not including the terminating zero.

I tried the code below and many other variations

$ll = 100;try this
    $struct_Buffer = DllStructCreate("char[" & $ll & "]");
    DllStructSetData($struct_Buffer,1,$ll,1)
    $erBuf = DllStructCreate('int')
    $szBuf = DllStructCreate('int')
    $Res = DllCall('wininet.dll','int', 'InternetGetLastResponseInfo','int_ptr',DllStructGetPtr($erBuf),'ptr',DllStructGetPtr($struct_Buffer),'int_ptr',DllStructGetPtr($szBuf))
    $LstErr = DllStructGetData($erBuf, 1)
    $ErrStrg = DllStructGetData($struct_Buffer, 1)

But this doesn't work.

Since I don't understand how to create the pointers and how to refer to them I am doomed to fail.

Can someone give me some clues?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Like in C you're supposed to have a buffer to receive that information.

Let's make a little translating:

unsigned long iError;
char szBuffer[200];
unsigned long iBufferLength = 200;

InternetGetLastResponseInfo (&iError, szBuffer, &iBufferLength);

$iError = DllStructCreate ("int")
$szBuffer = DllStructCreate ("char[200]")
$iBufferLength = DllStructCreate ("int")
DllStructSetData ($iBufferLength, 1, 200)

DllCall ("wininet.dll", "int", "InternetGetLastResponseInfo", _
    "ptr", DllStructGetPtr ($iError), _
    "ptr", DllStructGetPtr ($szBuffer), _
    "ptr", DllStructGetPtr ($iBufferLength) _
)
Edited by CoePSX

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

Like in C you're supposed to have a buffer to receive that information.

Let's make a little translating:

unsigned long iError;
char szBuffer[200];
unsigned long iBufferLength = 200;

InternetGetLastResponseInfo (&iError, szBuffer, &iBufferLength);

$iError = DllStructCreate ("int")
$szBuffer = DllStructCreate ("char[200]")
$iBufferLength = DllStructCreate ("int")
DllStructSetData ($iBufferLength, 1, 200)

DllCall ("wininet.dll", "int", "InternetGetLastResponseInfo", _
    "ptr", DllStructGetPtr ($iError), _
    "ptr", DllStructGetPtr ($szBuffer), _
    "ptr", DllStructGetPtr ($iBufferLength) _
)

Thanks for your reply CoePSX.

The only change you have made to my code is that you have changed 'int_ptr' to 'ptr', so I'm not sure what you mean by a translation.

I have tried your suggestion but this makes no difference, I still get nothing back for the error message or the error number.

What I need is someone who has used this function or an example of its use somewhere and searching for InternetGetLastResponseInfo only brings up my posts.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

If the function call fails then @error is set to 1. Otherwise an array is returned that contains the function return value and a copy of all the parameters (including parameters that the function may have modified).

$return[0] = function return value

$return[1] = param1

$return[2] = param2

...

$return[n] = paramn

Taking that as a base you could also use a different approach, without using the DllStructs.

Look at this:

$Result = DllCall ("wininet.dll", "int", "InternetGetLastResponseInfo", _
    "str", "", _
    "str", "", _
    "int", 0 _
)

; The empty strings got filled by the function, so we get their values
$iError = $Result[1]
$szBuffer = $Result[2]

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Link to comment
Share on other sites

Taking that as a base you could also use a different approach, without using the DllStructs.

Look at this:

$Result = DllCall ("wininet.dll", "int", "InternetGetLastResponseInfo", _
    "str", "", _
    "str", "", _
    "int", 0 _
)

; The empty strings got filled by the function, so we get their values
$iError = $Result[1]
$szBuffer = $Result[2]
I tried that but I still get nothing. Maybe the problem is there should be nothing. If I try an FTP function and GetLastError is 12003 then my understanding is that I should be able to see the error by using InternetGetLastResponseInfo, but no matter what I've tried so far, despite the fact that I get error 12003, I cannot get information on the error.

Maybe sitting in a cave with a spinning wheel for 100 years is not such a bad idea.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Maybe sitting in a cave with a spinning wheel for 100 years is not such a bad idea.

If I'm not wrong someone have already done that. I believe that's how the bike came along.

Maybe the function is just correctly returning 0.

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

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...