muchado Posted April 30, 2014 Posted April 30, 2014 I have read all the way through the following forum entry, but I cannot work out how to use it in my case. '?do=embed' frameborder='0' data-embedContent>> Please could someone explain to me how I can include a DLL in a compiled script - I would like to have a single executable that includes everything. It seems from reading through the previous postings that some of the solutions presented are now superseded (such as MemoryDLL). Do I still need to convert my DLL into a HEX format? Does MemoryDLLGen still exist (it is not in the Help file)? If I use DLLCall in my script, will the comopiler package the DLL up inside the executable? The DLL was created using .NET Does the DLL need any special library to be included in it? Sorry if these questions are a little incoherent - I have pretty much got familiar with basic functions in AutoIT (which is a great help, by the way), but I am getting stuck here due to lack of experience.
muchado Posted April 30, 2014 Author Posted April 30, 2014 Here is the script that I am using: 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) I am getting the following result: 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 It seems that DLLOpen is not returning an error, but is returning an unexpected handle... Any pointers on what I am doing wrong? Also - if I can get this to work, will it end up being wrapped in the executable if I compile it?
Geir1983 Posted April 30, 2014 Posted April 30, 2014 You can embed a file in your executable with the fileinstall() fileinstall()
muchado Posted April 30, 2014 Author Posted April 30, 2014 Thanks Wayfarer. It sounds as though that will result in the DLL being extracted and installed during the running of the script, which is not ideal from my perspective, but it is certainly an option.
Solution Geir1983 Posted April 30, 2014 Solution Posted April 30, 2014 Just test like you do at the very beginning of the script, if the file is already installed do nothing. If the dll is not installed then use fileinstall to place it in your prefered location. Next time you start your executable script it will find the dll file and no further action (fileinstall() )necessary.
muchado Posted May 5, 2014 Author Posted May 5, 2014 Just test like you do at the very beginning of the script, if the file is already installed do nothing. If the dll is not installed then use fileinstall to place it in your prefered location. Next time you start your executable script it will find the dll file and no further action (fileinstall() )necessary. Thanks for the response. Presumably this means that the DLL will end up outside the executable once it is executed. That is not necessarily a problem, but I would have preferred not to confuse the user with another file appearing. PS Any idea why the DLL is found, but the reported handle is wrong?
Geir1983 Posted May 5, 2014 Posted May 5, 2014 If you place the dll in @SystemDir i doubt the user will ever know. For the return, try to not show it as an array (error means variable is not array), does the arraydisplay show you an array? ;_ArrayDisplay($aDLL) MsgBox(0, "", $aDLL)
muchado Posted May 13, 2014 Author Posted May 13, 2014 Thanks for all your help on this. $aDLL does not appear to be an array. It appears that there is a problem in the way that I am calling the DLL, which is why I am not receiving an array in return. I think I know what to do to fix it now. Thanks.
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