Sign in to follow this  
Followers 0
xwinterx

Help Using a DLL

8 posts in this topic

#1 ·  Posted (edited)

I want to use a DLL in my AutoIt code. But my problem is I am not sure how to ObjCreate it. Here is what I know of the DLL:

NameSpace: MathLib

Class: MathFuncs

Functions: Add(double a, double :P

All it does is add a and b together. I tried creating the object as ObjCreate("MathLib.MathFuncs") but I get an error. Any help? I can provide the full DLL source code once I am at home.

Here is my Code:

$dll = DllOpen(@ScriptDir & "\MathLib.dll")

If @error Then
    MsgBox(4096, "Fail!", "MathLib failed to open.")
Else
    MsgBox(4096, "Success!", "MathLib successfully opened!")
EndIf

$result = DllCall($dll, "dword", "Add", "dword", 1, "dword", 2)

If @error Then
    MsgBox(4096, "Fail!", "Failed to execute DllCall! #" & @error)
Else
    MsgBox(4096, "Success!", "Result: " & $result[0])
EndIf

DllClose($dll)

and the DLL is attached. Keep getting @error at 3, "function not found in DLL"

MathLib.dll

Edited by xwinterx

Share this post


Link to post
Share on other sites



Sounds like this is a regular dll, not an COM object. When this is the case you will have to use DllCall().

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

DllCall ( "dll", "return type", "function" [, "type1", param1 [, "type n", param n]] )


READ BEFORE POSTINGMy UDF'sMessagesYou say plz because its shorter than please. I say no because its shorter than yes.Join My Website

Share this post


Link to post
Share on other sites

Sounds like this is a regular dll, not an COM object. When this is the case you will have to use DllCall().

Jos

Beaten to the punch. (We posted at the exact same time)


READ BEFORE POSTINGMy UDF'sMessagesYou say plz because its shorter than please. I say no because its shorter than yes.Join My Website

Share this post


Link to post
Share on other sites

I also tried DllOpen and DllCall with the same results, though I am sure I did it wrong. Here was my AutoIt Code:

$dll = DllOpen("MathLib.dll")

If @error Then
    MsgBox(4096, "Fail!", "MathLib failed to open.")
Else
    MsgBox(4096, "Success!", "MathLib successfully opened!")
EndIf

$result = DllCall($dll, "double", "Add", "double", 1, "double", 2)

If @error Then
    MsgBox(4096, "Fail!", "Failed to execute DllCall!")
Else
    MsgBox(4096, "Success!", "Result: " & $result)
EndIf



DllClose($dll)

It opens just fine. Oh well, I keep trying. :P DLL stuff has always been a mystery to me.

Share this post


Link to post
Share on other sites

"double" is not a valid type.

$result = DllCall($dll, "dword", "Add", "dword", 1, "dword", 2)

Just check the @error to understand what you are doing wrong:

Return Value

Success: @error = 0.

Failure: @error = 1 unable to use the DLL file,

@error = 2 unknown "return type",

@error = 3 "function" not found in the DLL file.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

"double" is not a valid type.

$result = DllCall($dll, "dword", "Add", "dword", 1, "dword", 2)

Just check the @error to understand what you are doing wrong:

thanks. tried it but get an error. I will look at it more later, it is time for bed and I have a headache from this. hehehe. thanks for the help guys!

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  
Followers 0