Jump to content

Help Using a DLL


Recommended Posts

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
Link to comment
Share on other sites

  • Developers

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

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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!
Link to comment
Share on other sites

  • Developers

Don't forget that the returned information is an Array.

Just look at the Example in the HelpFile.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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