muchado Posted May 5, 2014 Share Posted May 5, 2014 I have written a script that I want to use to call a DLL. However, when I call it using DLLOpen, it returns an integer rather than a handle. This would make sense if it was a "-1" error code, but instead it is a "1". If FileExists ( @SystemDir & "\MyDLL.dll" ) Then ConsoleWrite ( "DLL exists and is located here: " & @SystemDir & @CRLF ) Else ConsoleWrite ( "DLL not found in " & @SystemDir & @CRLF ) Exit EndIf Global $hDll = DllOpen(@SystemDir & "\MyDLL.dll") ConsoleWrite ( "DLLOpen MyDLL returns " & $hDLL & @CRLF ) If $hDll = -1 Then Exit MsgBox(0, "", "Failed to open MyDLL.dll") Global $aDLL = DllCall($hDLL, "BOOL", "Output", "str", "AdSec_Driver", "str", "ETABS" ) ConsoleWrite("!" & @error & "-" & @extended & @CRLF) ConsoleWrite ( "MyDLL returns data of type " & VarGetType( $aDLL) & @CRLF ) _ArrayDisplay($aDLL) MsgBox(0, "", $aDLL[0]) DllClose($hDll) When I run this I get the following output on the console: DLL exists and is located here: C:\Windows\system32 DLLOpen MyDLL returns 1 !3-0 MyDLL returns data of type Int32 "C:\Users\andrew.mole\Documents\autoit\AdSec_Driver\trunk\AdSec_Driver.au3" (197) : ==> Subscript used on non-accessible variable.: MsgBox(0, "", $aDLL[0]) MsgBox(0, "", $aDLL^ ERROR Any idea why this is? Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted May 5, 2014 Share Posted May 5, 2014 Look at the @error set by DllCall (3) the documentation says that this means ""function" not found in the DLL file,". muchado 1 "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
Solution funkey Posted May 5, 2014 Solution Share Posted May 5, 2014 DllOpen never returns a real valid handle. AutoIt hides it for you and you just get an identifier from DllOpen. But you can use it like a handle within the AutoIt functions. As DatMCEyeBall said, there is another problem: The function name is not found in the DLL. Use a tool like dependency walker or DLLEXP to see what is the right name. I think your function name got decorated by the compiler. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
JohnOne Posted May 5, 2014 Share Posted May 5, 2014 ^ Same as FileOpen will return 1. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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