Jump to content

Problems working out how to embed a DLL inside a compiled script


Go to solution Solved by Geir1983,

Recommended Posts

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.

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • Solution

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

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