Jump to content



Photo

Help with DLL function caal translation to Autoit format


  • Please log in to reply
5 replies to this topic

#1 nicdev007

nicdev007

    Seeker

  • Active Members
  • 11 posts

Posted 28 February 2012 - 10:47 AM

Hi All,

First off I have to say what a great product! Autoit is easy to learn and use (reminds me of Basic days), and for simple GUI projects it is light and ideal. Great job.

I have been following the tutorials and posts on DLL calls, as this is something that would add another edge to the GUI script I have running, but I still cannot get my head around it somehow ... I have tried to understand how one could translate the data types to AutoIt format but after same days of battling I am posting here for help.

In the original Dll.h file the function is declared like this:
/** * DLLGetHidString: * Get HID object value with string format * @return 1 if no error *    0 if an error occurs */ MyDLL_DECL int MyDLLGetHidString(const char* objectName, char* sValue);


So what I have been trying is this:

Local $dll = DllOpen(MyDLL.dll) ; open DLL Local $result = DllCall($dll, "int:cdecl", "MyDLLGetHidString", "str", "StringtoQuery", "str", "value") MsgBox(0, "DLL:", "error is:" & @error & @LF &@LF & EchoArray($result)) DllClose($dll)


I get "error is:0"
the 2 x LF

then
"0" + LF
"StringtoQuery" + LF
"res"

What I don't seem to get is the actual result of my query ... the @error=0 means my call to the function was ok though ...

Any ideas and help is greatly appreciated.

Best regards
Nicdev
Life is too short to worry about the things you don't have or cannot do ...So if you don't know how to do it - Learn it!Don't be afraid to ask for help ...







#2 Andreik

Andreik

    Bishop

  • Active Members
  • PipPipPipPipPipPip
  • 2,498 posts

Posted 28 February 2012 - 12:31 PM

Please attach your dll code or compiled dll to make some tests.
When the words fail... music speaks

#3 funkey

funkey

    New Dad

  • Active Members
  • PipPipPipPipPipPip
  • 484 posts

Posted 28 February 2012 - 02:40 PM

DllCall returns an array. So the result is in $result[2].

Edit: I see you get "res" there, so I think DllCall works right and everything is OK.

Edited by funkey, 28 February 2012 - 02:42 PM.

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.


#4 nicdev007

nicdev007

    Seeker

  • Active Members
  • 11 posts

Posted 29 February 2012 - 08:51 AM

Please attach your dll code or compiled dll to make some tests.

Hi Andreik,
I prefer to mail it to you as it is not my property and I'm not sure of the implications if I post it directly here :-) Or even upload it to a fileshare if you prefer. PM me your email.

Thanks for the reply.

DllCall returns an array. So the result is in $result[2].

Edit: I see you get "res" there, so I think DllCall works right and everything is OK.

Hi Funkey,
Thanks for the feedback. I though the result was in $result[0]? I think the same as you that the Dll call works ok, I think the ",
char* sValue" (second parameter in original dll file) must be a pointer or some sort of buffer reference.

Regards
Nicdev
Life is too short to worry about the things you don't have or cannot do ...So if you don't know how to do it - Learn it!Don't be afraid to ask for help ...

#5 funkey

funkey

    New Dad

  • Active Members
  • PipPipPipPipPipPip
  • 484 posts

Posted 29 February 2012 - 09:32 AM

$result[0] contains the integer returned. I think it is 0 when everything is OK, and nonzero (1) if an error occurs.
In result[1] there is the string given to the DLL ("StringtoQuery" in your case). This is a CONST string. So it stays the same.
In result[2] there I think the DLL returns the result of the function. You just need to give an empty string to the DLL and it is filled by the DLL-function.
Of course I do not know the DLL and this function, I just think this should be that way.

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.


#6 nicdev007

nicdev007

    Seeker

  • Active Members
  • 11 posts

Posted 19 April 2012 - 04:47 PM

Hi again Andreik and funkey.

I am posting now because I solved the issue (yes you can say: "finally!"). I thank you guys anyway for your help because you helped me keep looking in the right places. After many hours of playing around and running serial port traces, the fix was quite easy, and only has to do with "how" the DLL works.

When I was calling the DLL function before the communication to my appliance was not initialised (first function in the DLL but not documented). thus for me to get a good reply I just needed to first call the initialise function and then my query :-)
Now it works like a charm:

Local $dll = DllOpen(MyDLL.dll) ; open DLL Local $InitDLL = DllCall($dll, "int:cdecl", "MyDLLInitialize") ; Initialize the device ; do some error checking here Local $result = DllCall($dll, "int:cdecl", "MyDLLGetHidString", "str", "HIDobjectName", "str", $value) ; get the HID value MsgBox(0, "DLL result:", "The result is:" & @CRLF & $result [2]) DllClose($dll)


Thanks again, and in any event what a great learning curve!

Best regards
Nicdev
Life is too short to worry about the things you don't have or cannot do ...So if you don't know how to do it - Learn it!Don't be afraid to ask for help ...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users