Jump to content

Send pointer with autoit?


Recommended Posts

Hello,

I am trying to work with a dll that requires a pointer (char*) but I have no idea how to pass this pointer using autoit!

The first line is the code in the dll that I want to call, and the second line is how I call it in Autoit.

XXX_API int GetElement( int iParamID, int iTypeID, int iPsetID, char* pValue, int iMaxLen );

Dim $x
$result2 = DllCall("C:\MYDLL.dll", "int", "GetElement", "int", 254, "int", 1, "int", 0, "ptr", $x, "int", 64)

Am I doing it wrong? How do you send a pointer with autoit?

Link to comment
Share on other sites

1st you'll need the beta version, once you have that look into DllStruct functions

<{POST_SNAPBACK}>

NO! A char* is "str" type. Learn these things people and stop complicating things!

Sorry, gafrost, this isn't directed so much at you, its just a major annoyance of mine to see people write asinine code using DllStruct* when DlLCall()'s basic supported types can do the job. I've seen this type of code too many times:

Local $struct = DllStructCreate("int")
DllCall("dll", "int", "Function", "ptr", DllStructGetPtr($struct))
; ...

That is stupid! Use:

Local $aRet = DllCall("dll", "int", "Function", "int_ptr", "")
; $aRet[1] is the value returned in the first argument

If people don't understand the basic types supported by DllCall(), then they don't need to be using the function. DllStruct* is not needed in 70% of calls. It is necessary if the function requires a structure. C intrinsic types are natively supported up to at least one level of pointer dereferencing (NOTE: If you do not understand the previous sentence, you do not need to be using DllCall()).

Link to comment
Share on other sites

That is stupid!  Use:

Local $aRet = DllCall("dll", "int", "Function", "int_ptr", "")
; $aRet[1] is the value returned in the first argument

If people don't understand the basic types supported by DllCall(), then they don't need to be using the function.  DllStruct* is not needed in 70% of calls.  It is necessary if the function requires a structure.  C intrinsic types are natively supported up to at least one level of pointer dereferencing (NOTE: If you do not understand the previous sentence, you do not need to be using DllCall()).

<{POST_SNAPBACK}>

Ok, I got mine working (using dllstruct, but going to attempt your way next), but I want to make sure I understand your answer. Are you saying that $aRet[0] is the retun value (in my case an error code) and $aRet[1] would be the value in the pointer (the answer I am retrieving)? I wish that the doc would clarify that a bit, but thank god for knowledgeable people like you. It's also very entertaining reading your posts because your posts always come off as angry and annoyed (but highly informative). You remind me of a professor I had that could not stand it when students asked questions. He was a fun one. As strange as it may seem, I'm not actually being sarcastic, although it sure reads like I am...
Link to comment
Share on other sites

Yes... From Help File

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

Link to comment
Share on other sites

$result2 = DllCall($dll, "int", "GetElement", "int", 645, "int", 0, "int", 0, "int_ptr", "", "int", 64)

Msgbox(0,"ok Y", $result[1])

gives me:

Z:\dasa\AutoIt\test.au3 (23) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

Msgbox(0,"ok Y", $result[1])

While when I did it this way:

$struct=DllStructCreate("char[128]")
DllStructSetData($struct,1,$in)
$result2 = DllCall($dll, "int", "GetElement", "int", 644, "int", 0, "int", 0, "ptr", DllStructGetPtr($struct,1), "int", 64) 
$mmPerPx = DllStructGetData($struct,1)
Msgbox(0,"ok Y", $mmPerPx)

I got the correct answer. Did I do it wrong?

Link to comment
Share on other sites

But the variable is $result2[1] and not $result[1].You ask it to show you a variable that doesnt exist....

<{POST_SNAPBACK}>

My mistake, however I still don't get the correct answer. It gives me 645. When I change it to $result2[1] through $result2[5] none of them are the correct answer... all of them give me the same answer I put in, or for the ptr, it gives me 94508 when I know it is .247....

EDIT: I changed 'int_ptr' to 'str' and it worked..... Thanks for the help, now I think I actually understand dllcall and how to use it.

Edited by Arrrghmatey
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...