Jump to content
Sign in to follow this  
nicdev007

Help with DLL function caal translation to Autoit format

Recommended Posts

nicdev007

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

Share this post


Link to post
Share on other sites
Andreik

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


When the words fail... music speaks

Share this post


Link to post
Share on other sites
funkey

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

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.

Share this post


Link to post
Share on other sites
nicdev007

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

Share this post


Link to post
Share on other sites
funkey

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

Share this post


Link to post
Share on other sites
nicdev007

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

Share this post


Link to post
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
Sign in to follow this  

×