xwinterx Posted August 10, 2008 Share Posted August 10, 2008 (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 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 August 10, 2008 by xwinterx Link to comment Share on other sites More sharing options...
Developers Jos Posted August 10, 2008 Developers Share Posted August 10, 2008 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 More sharing options...
2words4uready Posted August 10, 2008 Share Posted August 10, 2008 DllCall ( "dll", "return type", "function" [, "type1", param1 [, "type n", param n]] ) Link to comment Share on other sites More sharing options...
2words4uready Posted August 10, 2008 Share Posted August 10, 2008 Sounds like this is a regular dll, not an COM object. When this is the case you will have to use DllCall().JosBeaten to the punch. (We posted at the exact same time) Link to comment Share on other sites More sharing options...
xwinterx Posted August 10, 2008 Author Share Posted August 10, 2008 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. DLL stuff has always been a mystery to me. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 10, 2008 Developers Share Posted August 10, 2008 "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 More sharing options...
xwinterx Posted August 10, 2008 Author Share Posted August 10, 2008 "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 More sharing options...
Developers Jos Posted August 10, 2008 Developers Share Posted August 10, 2008 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now