james3mg Posted October 16, 2007 Share Posted October 16, 2007 (edited) It's likely this tool is already out there, but I did a search and couldn't find it, so I made it instead. It might be helpful to others, so I figured I'd post it, too. Running this script will prompt you for a .dll file, then read it and write the contents into an .au3 file that you can #include in a script to bundle (for instance) a COM .dll file with your script. Note that you'll still need to include functions similar to _SQLite_Start() once this is included, as it doesn't actually CREATE the dll anywhere when called - it just stores the information in such a way that your SCRIPT can write it easily. Edit: I should have mentioned (in fact, I thought I did) that the resulting au3 file matches the format of the SQLite.dll.au3 file in AutoIt's include directory (line for line, except for the dll-specific stuff that gets written dynamically...yes, I just copied that file as my template), so you can follow the corresponding SQLite.au3 include file to see how to actually use this to write the .dll file, etc. I used this to start working with ImageMagickObject.dll - hopefully I can get a reasonable UDF developed from this, though I've never messed around with dlls before, so it'll be an adventure! But I digress...here's the Dll2Au3 script: expandcollapse popupDim $OrigDLL=FileOpenDialog("Select a .dll to include","","DLL files (*.dll)") If @error OR NOT FileExists($OrigDLL) Then Exit Dim $TheFile=FileOpen($OrigDLL,16) If @error Then QuitMe("File could not be opened") Dim $TheStr=Hex(FileRead($TheFile)) If @error Then QuitMe("File could not be read") Dim $InlineAu3File=FileSaveDialog("Save inline file as","","au3 script (*.au3)",18,StringTrimLeft($OrigDLL,StringInStr($OrigDLL,"\",0,-1))&".au3") If @error Then Exit If NOT StringInStr(StringTrimLeft($InlineAu3File,StringInStr($InlineAu3File,"\",0,-1)),".") Then $InlineAu3File&=".au3" $InlineAu3File=FileOpen($InlineAu3File,2) FileWriteLine($InlineAu3File,";Inline "&StringTrimLeft($OrigDLL,StringInStr($OrigDLL,"\",0,-1))&", Creation Time: "&@YEAR&"/"&@MON&"/"&@MDAY&" "&@HOUR&":"&@MIN&":"&@SEC) FileWriteLine($InlineAu3File,"#include-once") FileWriteLine($InlineAu3File,"Func __"&StringReplace(StringTrimLeft($OrigDLL,StringInStr($OrigDLL,"\",0,-1)),".dll","")&"_Inline_Modified()") FileWriteLine($InlineAu3File,@TAB&'Return "'&@YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC&'" ; '&@YEAR&'/'&@MON&'/'&@MDAY&' '&@HOUR&':'&@MIN&':'&@SEC) FileWriteLine($InlineAu3File,"EndFunc") FileWriteLine($InlineAu3File,"Func __"&StringReplace(StringTrimLeft($OrigDLL,StringInStr($OrigDLL,"\",0,-1)),".dll","")&"_Inline_Version()") FileWriteLine($InlineAu3File,@TAB&'Return "'&InputBox("Version number:","Enter the version number of this dll","1")&'"') FileWriteLine($InlineAu3File,"EndFunc") FileWriteLine($InlineAu3File,"Func __"&StringReplace(StringTrimLeft($OrigDLL,StringInStr($OrigDLL,"\",0,-1)),".dll","")&"_Inline_"&StringReplace(StringTrimLeft($OrigDLL,StringInStr($OrigDLL,"\",0,-1)),".","")&"() ; Dont Tidy me!") FileWriteLine($InlineAu3File,"Local $sData") Dim $i=1 Dim $ExitWhenDone=0 While 1 Local $CurrLine=StringMid($TheStr,$i*4082-4081,4082) If StringLen($CurrLine) <> 4082 Then $ExitWhenDone=1 FileWriteLine($InlineAu3File,'$sData &= "'&$CurrLine&'"') If $ExitWhenDone Then ExitLoop $i+=1 WEnd FileWriteLine($InlineAu3File,'Return Binary("0x" & $sData)') FileWriteLine($InlineAu3File,"EndFunc") FileClose($TheFile) FileClose($InlineAu3File) MsgBox(0,"Done","Inline dll written to au3") Func QuitMe($_message="") If $_message <> "" Then MsgBox(16,"Error",$_message) FileClose($TheFile) FileClose($InlineAu3File) Exit EndFunc Edited October 16, 2007 by james3mg "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
Pascal257 Posted October 16, 2007 Share Posted October 16, 2007 Very cool idea! If this really workes, its just that easy to add cool features to a script using a dll. Good work, Pascal Link to comment Share on other sites More sharing options...
james3mg Posted October 16, 2007 Author Share Posted October 16, 2007 Very cool idea!If this really workes, its just that easy to add cool features to a script using a dll.Good work,PascalThanks It does work - it's the same format that the SQLite udf that's included with AutoIt uses - I liked how easy it was to include SQLite functions because of this structure, and I wanted to be able to do the same thing with Image Magick...I just couldn't find the tool to actually compile a dll into an au3! Hence, this script. I meant to make copious mention in my first post that the idea and structure, etc were basically lifted straight from the SQLite udf files, but seems I missed mentioning that. I've fixed that now To see how to go ahead and use the #include file this generates, follow the ideas in the SQLite.au3 include file...specifically, you'll need a similar <whatever>Startup() command for your specific inline dll to call the function in your created au3 include, write the data to a temporary dll file, open the dll, etc. Again, the file this script creates is (very) similar to SQLite.dll.au3, so you'll want to make another include file that's similar to SQLite.au3 in your includes directory. "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
BillLuvsU Posted October 16, 2007 Share Posted October 16, 2007 Thats really cool stuff. Hope it works out for you! [center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw Link to comment Share on other sites More sharing options...
martin Posted October 16, 2007 Share Posted October 16, 2007 (edited) It's likely this tool is already out there, but I did a search and couldn't find it, so I made it instead. It might be helpful to others, so I figured I'd post it, too.What is the advantage of this method over FileInstall?mgrefdlltoau3 Edited May 15, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
DirtDBaK Posted October 16, 2007 Share Posted October 16, 2007 well looks like nice work, but nothing I would need! Keep up the great scripting! [center][/center] Link to comment Share on other sites More sharing options...
james3mg Posted October 16, 2007 Author Share Posted October 16, 2007 What is the advantage of this method over FileInstall?Good question - primarily its advantage is the ability to include dll-dependant functions in a UDF - since you can't use FileInstall in a UDF you want to be included with AutoIt - this is as close as you can come to including a file in an .au3 script, rather than a .exe program.Again I refer you to the SQLite UDF example I got this structure from - since all the SQLite functions rely on actually calling functions in the SQLite.dll file, they couldn't publish a UDF with the required .dll file, so they included it in this way in the actual au3 file itself, and let it write the necessary dll file at runtime. Does that make sense? "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 Link to comment Share on other sites More sharing options...
martin Posted October 16, 2007 Share Posted October 16, 2007 Good question - primarily its advantage is the ability to include dll-dependant functions in a UDF - since you can't use FileInstall in a UDF you want to be included with AutoIt - this is as close as you can come to including a file in an .au3 script, rather than a .exe program.Again I refer you to the SQLite UDF example I got this structure from - since all the SQLite functions rely on actually calling functions in the SQLite.dll file, they couldn't publish a UDF with the required .dll file, so they included it in this way in the actual au3 file itself, and let it write the necessary dll file at runtime. Does that make sense?Yup, that makes perfect sense. Thanks for your reply, I can see the possible benefits now. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ptrex Posted October 17, 2007 Share Posted October 17, 2007 @james3mg Very interesting experiment !! I Like very much the creativity that some people show in this AutoIT forum !! Like myself I have done some AU3 that I would never thought it was possible. One question though : You are referring to reading a COM DLL into a UDF ? But what about not having it registered on your machine, I doubt this would work, correct ? regards ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
martin Posted October 17, 2007 Share Posted October 17, 2007 @james3mgVery interesting experiment !! I Like very much the creativity that some people show in this AutoIT forum !!Like myself I have done some AU3 that I would never thought it was possible.One question though :You are referring to reading a COM DLL into a UDF ?But what about not having it registered on your machine, I doubt this would work, correct ?regardsptrexI don't expect that this will be a problem. All you're doing is 'carrying' the dll in a text format in the udf so that you can save it as a dll then use it when you want to. The dll can be called without being registered if you know its path which you will, or you can always register it in case you want other apps to use it, and it won't matter if it's already registered. (I don't know how to check if a dll is already registered.) Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ptrex Posted October 17, 2007 Share Posted October 17, 2007 @martin That's exactly what I meant. (Maybe not quite clearly specified in my comments ) When writing a DLL or a COM DLL back to the system, this makes a difference. So for people not to be confused. If it concernes a COM DLL, there's one extra step that needs to be done is registering it on the local machine. For some of us it is obvious for others it's not. Regards, ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Automan Empire Posted October 17, 2007 Share Posted October 17, 2007 I tried it, and I like it. It will convert any dll file to an AU3 #Include File. "I've seen your work in the past, and it's novice at best..." SmOke_N Link to comment Share on other sites More sharing options...
james3mg Posted October 17, 2007 Author Share Posted October 17, 2007 (edited) @martinThat's exactly what I meant. (Maybe not quite clearly specified in my comments )When writing a DLL or a COM DLL back to the system, this makes a difference. So for people not to be confused. If it concernes a COM DLL, there's one extra step that needs to be done is registering it on the local machine.For some of us it is obvious for others it's not.Regards,ptrexThat's true...thanks to both of you for clarifying my comments. You can't do COM without it being registered, but you can call functions from a dll using DLLCall() without it being registered. Edited October 17, 2007 by james3mg "There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110 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