Leaderboard
Popular Content
Showing content with the highest reputation on 06/06/2019 in all areas
-
Fork UDF (ish)
CoffeeJoe and one other reacted to argumentum for a topic
Forking and threading. They both do stuff while another loop or event handler, does it's thing. Load a DLL, and ask for a function or procedure to run, and it'll do it. Handling all those takes time waiting, or to come up with semaphores and mutex and what not. So the issue at times is that we want to have all that in AutoIt and there comes the OMGs. To me, it all comes to run something and not get the main loop stuck waiting, unresponsive, as if frozen. ( oh, there is no threading in AutoIt, what can I do ! ) Hence this UDFish ( I'm not good at technical writing 😕 ), that has these functions: #cs === User Calltips: =============================================================================================== _Fork_Startup() Init. UDF - Place on your main script once everything is declared. _Fork_StartupOnFailMsgBox([$ShowMsgBox = Default]) Default = (not @compiled), True = Show error MsgBox(), False = Do Not show error MsgBox() _Fork_Func([$sFunction = Default], [$vParameter = ""], [$sExtraCmdLine = ""], [$iUseBase64Cmd = 0], [$sVerb = ""]) Starts another Process and Execute or Call $sFunction, Returns PID. _Fork_SetReceiver([$sFunction = ""]) Register/Unregister IPC Receiver Function. _Fork_GetReceiver() Get IPC Receiver Function name. _Fork_GetParentPID() Get the parent PID. _Fork_GetWinInfos([$AutoItWinTitlePrefix = Default],[ $ForkPID = ""]) Get an array of Forked Processes _Fork_CallArgArraySeparatorChar($sChar = Default) Default = Opt("GUIDataSeparatorChar") _Fork_AutoItWinTitlePrefix([$sPrefix = Default]) Returns the prefix, or set it by passing a new string. _Fork_ForkReceiverGuiTitlePrefix([$sPrefix = Default]) Returns the prefix, or set it by passing a new string. _Fork_ProcessGetWinList($vProcess, $sTitle = Default, $iOption = 0) Enumerates Windows of a Process. _Fork_WaitForReceiver($iPidChild, [$iTimeout = 60 Sec]) wait for _Fork_SetReceiver() to load via AutoItWinSetTitle(). _Fork_WaitForFork($iPidChild, [$iTimeout = 60 Sec]) wait for _Fork_Func() to load via AutoItWinSetTitle(). _Fork_Send($vPidOrHWnd, $sMessage,[$iTimeout = 500 mSec],[$fAbortIfHung = True]) Send IPC Message to Process via PID or hWnd. _Fork_Broadcast($sMessage, [$iTimeout = 500 mSec], [$fAbortIfHung = True], [$iDelayMs = 0], [$iExcludeSelf = 1], [$WinCloseAll = 0]) Send IPC Message broadcast to all in _Fork_AutoItWinTitlePrefix(), see comments. _Fork_DuplicateHandle($dwSourcePid, $hSourceHandle, $dwTargetPid = @AutoItPID, $fCloseSource = False) Returns a Duplicate handle. _Fork_GetVerUDF() Returns the version of this UDF. _DbgAid_SetActive([$Active = Default]) Enable sending data for debug: Default = Auto (True if Win found), True = Enable, False = Disable. _DbgAid_GetActive() Query Active state. _DbgAid_GuiTitle([$sTitle = Default]) Get or Set the GUI title for the debug receiver. _DbgAid_SelfName([$sSelfName = Default]) Get or Set a short name to be identified by. _DbgAid_Send($sString[, $iForceType = Default]) Send a string to the debug GUI. _DbgAid_SendVia([$iType = Default / $e_ForkDbgAid_ViaCOPYDATA / $e_ForkDbgAid_ViaMailslot]) Get / Set _DbgAid_Send() type. #ce === User Calltips: =============================================================================================== I believe that, with these functions, one can run a function in any count of other PIDs, communicate back and forth with any of them, and a console of sorts, to send data to follow what is happening with those other instances. This is basically a rewrite of "Another Multi Process Helper" by @piccaso. The functions not ported, I decided to not port. The renamed functions, are renamed to simplify the understanding of what they do, from a view of a ... me I did this because I'll need it in an upcoming project, and share it to aid those, that may find this, simple to implement in their code. Try the examples from SciTE ( or your editor ) and read the code, as there are notes explaining how it works. As always, share your views and improvements. If you have coding questions, kindly place them in "AutoIt General Help and Support". _Fork_UDF(v2019.06.29d).zip ( current version )2 points -
Minimize program on focus loss - (Locked)
FrancescoDiMuro and one other reacted to Earthshine for a topic
oops, i didn't even notice that. just focused on function calls. so it's about games, and somehow I could feel it from my first post. LOL.2 points -
Get All Window's Controls
vergil250493 reacted to jdelaney for a topic
I've wanted to post this for a while. It's a great script to help debug control data....perfect scenario, when you have a 'Button' grouping, and spy tools cannot focus on those controls within the button bounds (groups). I also use it to verify that a given ID is not present more than once...if not, that's how I identify the control in future scripts. Output can be filtered by: 1) Filter by IsVisible 2) Filter by matching class (ex Button, Label, Static) 3) Filter by containing text #include <Array.au3> #include <WinAPI.au3> ConsoleWrite("Make your window active!" & @CRLF) Sleep(5000) GetAllWindowsControls(WinGetHandle("[ACTIVE]")) Func GetAllWindowsControls($hCallersWindow, $bOnlyVisible=Default, $sStringIncludes=Default, $sClass=Default) If Not IsHWnd($hCallersWindow) Then ConsoleWrite("$hCallersWindow must be a handle...provided=[" & $hCallersWindow & "]" & @CRLF) Return False EndIf ; Get all list of controls If $bOnlyVisible = Default Then $bOnlyVisible = False If $sStringIncludes = Default Then $sStringIncludes = "" If $sClass = Default Then $sClass = "" $sClassList = WinGetClassList($hCallersWindow) ; Create array $aClassList = StringSplit($sClassList, @CRLF, 2) ; Sort array _ArraySort($aClassList) _ArrayDelete($aClassList, 0) ; Loop $iCurrentClass = "" $iCurrentCount = 1 $iTotalCounter = 1 If StringLen($sClass)>0 Then For $i = UBound($aClassList)-1 To 0 Step - 1 If $aClassList[$i]<>$sClass Then _ArrayDelete($aClassList,$i) EndIf Next EndIf For $i = 0 To UBound($aClassList) - 1 If $aClassList[$i] = $iCurrentClass Then $iCurrentCount += 1 Else $iCurrentClass = $aClassList[$i] $iCurrentCount = 1 EndIf $hControl = ControlGetHandle($hCallersWindow, "", "[CLASSNN:" & $iCurrentClass & $iCurrentCount & "]") $text = StringRegExpReplace(ControlGetText($hCallersWindow, "", $hControl), "[\n\r]", "{@CRLF}") $aPos = ControlGetPos($hCallersWindow, "", $hControl) $sControlID = _WinAPI_GetDlgCtrlID($hControl) $bIsVisible = ControlCommand($hCallersWindow, "", $hControl, "IsVisible") If $bOnlyVisible And Not $bIsVisible Then $iTotalCounter += 1 ContinueLoop EndIf If StringLen($sStringIncludes) > 0 Then If Not StringInStr($text, $sStringIncludes) Then $iTotalCounter += 1 ContinueLoop EndIf EndIf If IsArray($aPos) Then ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[" & StringFormat("%4s", $aPos[0]) & "] YPos=[" & StringFormat("%4s", $aPos[1]) & "] Width=[" & StringFormat("%4s", $aPos[2]) & "] Height=[" & StringFormat("%4s", $aPos[3]) & "] IsVisible=[" & $bIsVisible & "] Text=[" & $text & "]." & @CRLF) Else ConsoleWrite("Func=[GetAllWindowsControls]: ControlCounter=[" & StringFormat("%3s", $iTotalCounter) & "] ControlID=[" & StringFormat("%5s", $sControlID) & "] Handle=[" & StringFormat("%10s", $hControl) & "] ClassNN=[" & StringFormat("%19s", $iCurrentClass & $iCurrentCount) & "] XPos=[winclosed] YPos=[winclosed] Width=[winclosed] Height=[winclosed] Text=[" & $text & "]." & @CRLF) EndIf If Not WinExists($hCallersWindow) Then ExitLoop $iTotalCounter += 1 Next EndFunc ;==>GetAllWindowsControls1 point -
Seems like a bug..
FrancescoDiMuro reacted to Jos for a topic
Post a simple script that shows your issue and we'll explain why it is happening and how to solve it. Jos1 point -
Positions of searchstring in a string
Earthshine reacted to Gianni for a topic
... a simple example #include <array.au3> ; used to see result Local $sMyString = "111AB11111111AB11AB111111AB11" Local $sMySearch = "AB" Local $aMyPositions = _StringFindAll($sMyString, $sMySearch) _ArrayDisplay($aMyPositions, "Positions") Func _StringFindAll($String, $sSearch, $iCasesense = 0) StringReplace($String, $sSearch, $sSearch) ; count how many occurrences (if any) Local $iOccurrences = @extended ; the number of replacements is stored in the @extended macro If $iOccurrences Then Local $aPositions[$iOccurrences] ; make room for results For $i = 1 To $iOccurrences $aPositions[$i - 1] = StringInStr($String, $sSearch, $iCasesense, $i) Next Return SetError(0, $iOccurrences, $aPositions) Else Return SetError(True) EndIf EndFunc ;==>_StringFindAll1 point -
Need help with StringRegExpReplace
FrancescoDiMuro reacted to Jos for a topic
It always helps when you post a scriptlet with the input data and current source to play and modify. Jis1 point -
Minimize program on focus loss - (Locked)
Earthshine reacted to Nine for a topic
You should read about forum rules, especially the part of game automation !1 point -
Local $hMagnify = WinWait("[CLASS:MagUIClass]")1 point
-
You could try capturing the packets and work from there, @FireFox has a UDF for this here.1 point
-
If so why don't you use IE UDF to access the webpage and read the UID from it ?1 point
-
Why not build your project using SQL alone? https://www.youtube.com/watch?v=MPSMH8w7nfw1 point
-
Make the context menu modeless. Add these two lines Local $hCM = GUICtrlGetHandle( $idContextmenu ) _GUICtrlMenu_SetMenuStyle($hCM, BitXOR(_GUICtrlMenu_GetMenuStyle($hCM), $MNS_MODELESS)) immediately after this line Local $idContextmenu = GUICtrlCreateContextMenu() You can repeat that for all context menus. Also add #include <GuiMenu.au3> at the top of the script.1 point
-
Child GUI Examples
boomingranny reacted to Skysnake for a topic
I don't often have occasion to use Child GUIs. I find the multitude of options confusing. The example below I made for my own purposes, to have a visual guide to what the various Style and Extended Style options lead to. Comments are much appreciated. This can be extended with many more examples and comments and why certain Styles are to preferred or avoided. Where certain types of Child GUIs are most suitable etc. The code is very basic. It is intended to show GUI Styles, not much else. ;~ ******************************************************************** ;~ Author: Skysnake ;~ ;~ Title: Demo various Child Gui options ;~ Updated: 2019.01.03 ;~ ;~ Function: A demo script, demonstrates various style & Extended ;~ style options for Child GUIs ;~ Comments, ideas and suggestions very welcome :) ;~ ;~ ******************************************************************** #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> #include <Constants.au3> #include <WinAPI.au3> #include <ButtonConstants.au3> #include <MsgBoxConstants.au3> ShowChildGuis() Func ShowChildGuis() Local $guiParent = GUICreate("The Parent GUI", 1200, 700, 0, 0) ;WHLT $idFilemenu = GUICtrlCreateMenu(" &Menu") $ButtonCancel = GUICtrlCreateButton("&Close", 0, 0, 80, 25) GUICtrlSetTip($ButtonCancel, "Click to close all") $ButtonShowChildGui = GUICtrlCreateButton("&Show", 0, 25, 80, 25) GUICtrlSetTip($ButtonShowChildGui, "Click to show a child GUI") ;~ #comments-start --- Toggle this and same code below to show context menu for parent or child Local $idContextmenu = GUICtrlCreateContextMenu() Local $idNewsubmenu = GUICtrlCreateMenu("This is a Context Menu", $idContextmenu) Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu) Local $idContextButton = GUICtrlCreateButton("Context", 0, 50, 80, 25) GUICtrlSetTip($idContextButton, "Right Click to see Context Menu") Local $idButtoncontext = GUICtrlCreateContextMenu($idContextButton) Local $idMenuAbout = GUICtrlCreateMenuItem("This is a Context Menu", $idButtoncontext) Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu) Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu) GUICtrlCreateMenuItem("", $idContextmenu) ; separator Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu) ;~ #comments-end --- Toggle this and same code below to show context menu for parent or child Local $DefaultChildGui = GUICreate("Default child gui", 300, 100, 300, 300, Default, Default, $guiParent) ;;;WHLT GUICtrlCreateLabel("Default attributes" & @CRLF & "Cannot move; cannot resize", 0, 0, 500, 200) GUICtrlSetBkColor(-1, $COLOR_aqua) $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($DefaultChildGui), $GWL_STYLE) $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($DefaultChildGui), $GWL_EXSTYLE) GUISetStyle(BitOR($iStyle, $WS_VISIBLE), $iExStyle, $DefaultChildGui) Local $gChildGuiwithMenu = GUICreate("A child gui with menu", 300, 100, 50, 100, $WS_VISIBLE, BitOR($WS_EX_WINDOWEDGE, $WS_EX_MDICHILD, $WS_THICKFRAME), $guiParent) ;;;WHLT GUICtrlCreateLabel("Menu" & @CRLF & "Can move; cannot resize", 0, 0, 500, 200) GUICtrlSetBkColor(-1, $COLOR_skyblue) $idFilemenu = GUICtrlCreateMenu(" &File ") Local $idFileMenuItem = GUICtrlCreateMenuItem("An item for the File menu ", $idFilemenu) GUICtrlCreateMenuItem("", $idFilemenu) ; create a separator line ; use same dimensions for GUI and its Label Local $iSizeWide = 300, $iSizeHi = 100 GUICreate("A child gui", $iSizeWide, $iSizeHi, 100, 200, $WS_VISIBLE, BitOR($WS_EX_WINDOWEDGE, $WS_EX_TOPMOST, $WS_EX_MDICHILD, $WS_THICKFRAME), $guiParent) ;;;WHLT GUICtrlCreateLabel("Can move; cannot resize" & @CRLF & "Always on top", 0, 0, $iSizeWide, $iSizeHi) GUICtrlSetBkColor(-1, $COLOR_red) GUICreate("Child Gui Resizable", 300, 100, 200, 50, BitOR($WS_POPUP, $WS_SIZEBOX, $WS_CLIPCHILDREN, $WS_VISIBLE), $WS_EX_MDICHILD, $guiParent) ;;;WHLT GUICtrlCreateLabel("Popup Cannot move; can resize" & @CRLF & "Background", 0, 0, 500, 200) ; $WS_CHILD, GUICtrlSetBkColor(-1, $COLOR_blue) ; toggle the line below :) ;$idBackgroundmenu = GUICtrlCreateMenu(" &Menu ") ; give it a menu GUICreate("Child GUI, caption, resize", 300, 100, 300, 100, BitOR($WS_VISIBLE, $WS_POPUP, $WS_CAPTION), BitOR($WS_EX_TOOLWINDOW, $WS_EX_MDICHILD, $WS_EX_ACCEPTFILES), $guiParent) GUICtrlCreateLabel("Popup With Caption: Can move; cannot resize", 0, 0, 500, 200) GUICtrlSetBkColor(-1, $COLOR_yellow) GUICreate("Child GUI, abc", 300, 100, 400, 150, BitOR($WS_POPUP, $WS_VISIBLE, 0), $WS_EX_MDICHILD, $guiParent) GUICtrlCreateLabel("Popup Cannot move; cannot resize", 0, 0, 500, 200) GUICtrlSetBkColor(-1, $COLOR_green) ; Child GUI below has a control ............................. ............................................. Local $gChildWithControls = GUICreate("Child GUI with Buttons", 400, 400, 500, 200, BitOR($WS_CAPTION, $WS_CHILD), -1, $guiParent) GUISetFont(14, $gChildWithControls) Local $cLabel = GUICtrlCreateLabel("Can move; cannot resize", 0, 0, 400, 50) GUICtrlSetBkColor($cLabel, $COLOR_white) Local $idChild_ButtonOkay = GUICtrlCreateButton("Okay", 0, 50, 80, 30) Local $idChild_ButtonHide = GUICtrlCreateButton("Hide", 0, 80, 80, 30) GUICtrlSetTip($idChild_ButtonHide, "Click to hide this child GUI") ;~ #comments-start --- Toggle this and same code below to show context menu for parent or child ;~ Local $idContextmenu = GUICtrlCreateContextMenu() ;~ Local $idNewsubmenu = GUICtrlCreateMenu("This is a Context Menu", $idContextmenu) ;~ Local $idNewsubmenuText = GUICtrlCreateMenuItem("text", $idNewsubmenu) ;~ Local $idContextButton = GUICtrlCreateButton("Context", 0, 110, 80, 30) ;~ GUICtrlSetTip($idContextButton, "Right Click to see Context Menu") ;~ Local $idButtoncontext = GUICtrlCreateContextMenu($idContextButton) ;~ Local $idMenuAbout = GUICtrlCreateMenuItem("This is a Context Menu", $idButtoncontext) ;~ Local $idMenuOpen = GUICtrlCreateMenuItem("Open", $idContextmenu) ;~ Local $idMenuSave = GUICtrlCreateMenuItem("Save", $idContextmenu) ;~ GUICtrlCreateMenuItem("", $idContextmenu) ; separator ;~ Local $idMenuInfo = GUICtrlCreateMenuItem("Info", $idContextmenu) ;~ #comments-end --- Toggle this and same code below to show context menu for parent or child GUISetState(@SW_HIDE, $gChildWithControls) ;.......................................................................................................... Local $gToolbar = GUICreate("A floating Tool Window", 300, 50, 100, 25, $WS_VISIBLE, $WS_EX_TOOLWINDOW, $guiParent) GUICtrlCreateLabel("A floating toolbar", 0, 0, 500, 200) ; this does not show :) GUICtrlSetBkColor(-1, $COLOR_lime) ;~ $iStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($gToolbar), $GWL_STYLE) ;~ $iExStyle = _WinAPI_GetWindowLong(GUICtrlGetHandle($gToolbar), $GWL_EXSTYLE) ; BitOR($WS_EX_TOOLWINDOW, $WS_EX_MDICHILD) ;~ GUISetStyle(BitOR($iStyle, $WS_VISIBLE), $iExStyle, $gToolbar) $idToolmenu = GUICtrlCreateMenu(" &Tool ") Local $idToolMenuItem = GUICtrlCreateMenuItem("An item for the Tool menu ", $idToolmenu) Local $idToolMenuItemsecond = GUICtrlCreateMenuItem("A second item for the Tool menu ", $idToolmenu) GUICtrlCreateMenuItem("", $idToolmenu) ; create a separator line $idPrintmenu = GUICtrlCreateMenu(" &Print ") Local $idToolMenuItemPrint = GUICtrlCreateMenuItem("A Print item for the Toolbar print menu ", $idPrintmenu) GUICtrlCreateMenuItem("", $idPrintmenu) ; create a separator line #Region --- After GUI BEFORE loop starts GUISetState(@SW_SHOW, $guiParent) #EndRegion --- After GUI BEFORE loop starts While 1 ;Local $nMsg = GUIGetMsg() Switch GUIGetMsg() ; $nMsg Case $GUI_EVENT_CLOSE, $ButtonCancel GUIDelete($guiParent) ExitLoop Case $idContextButton MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'Right Click to see the Contect Menu') Case $ButtonShowChildGui GUISetState(@SW_ENABLE, $gChildWithControls) GUISetState(@SW_SHOW, $gChildWithControls) Case $idChild_ButtonHide ; <<<<<<<<<<<<<<< Child Gui Control Actioned in main loop ConsoleWrite("Yup, you clicked it" & @CRLF) GUISetState(@SW_HIDE, $gChildWithControls) Case $idChild_ButtonOkay ; <<<<<<<<<<<<<<< Child Gui Control Actioned in main loop ConsoleWrite("Yup, you clicked it" & @CRLF) MsgBox($MB_SYSTEMMODAL, "Button Clicked", 'Okay') EndSwitch WEnd GUIDelete() EndFunc ;==>ShowChildGuis1 point -
I couldn't reply as fast as you guys. I've something quite similar to what has been proposed but I've a doubt about the portability of the AutoIt *_key and *_rekey functions: if you supply a string you lose portability of the encrypted DB. Only if you feed an UTF-8 version of the string can you be guaranteed that the password will be the same across platforms and be independant of the locale used. Reason: Binary($somestring) will convert the string to ANSI then return the binary of the ANSI data. To ensure portability, you need to convert the string to UTF-8 and pass the struct buffer to the *key functions. I coded this in a bit of a hurry and I don't have time to test it right now, sorry. ; #FUNCTION# ==================================================================================================================== ; Name...........: _SQLite_Key ; Description ...: Specify the cryptographic key to use for a given encrypted Database (if you use system.data.sqlite.dll) ; Syntax.........: _SQLite_Key($hDB, $kKey) ; Parameters ....: $hDB - An Open Database, Use -1 to use Last Opened Database ; $kKey - key to be used, passed as a string or a binary variant ; Return values .: On Success - Returns $SQLITE_OK ; @error Value(s): -1 - SQLite Reported an Error (Check @extended Value) ; 1 - Library misuse (sqlite DLL not loaded or wrong DB handle) ; 2 - Error while converting key string to UTF-8 ; 3 - Error Calling SQLite API 'sqlite3_key' ; @extended Value(s): Can be compared against $SQLITE_* Constants ; Author ........: jchd ; Remarks .......: this call won't work with the standard version of sqlite3.dll which doesn't support encryption. ; Alternative libraries like system.data.sqlite _do_ support encryption and will work with this function. ; This function needs to be invoked right after an _SQLite_Open call and before any other call to _SQLite_* functions. ; =============================================================================================================================== Func _SQLite_Key($hDB, $kKey) If Not $g_hDll_SQLite Then Return SetError(1, $SQLITE_MISUSE, -1) If __SQLite_hChk($hDB, 2) Then Return SetError(1, $SQLITE_MISUSE, -1) Local $iKeyLen, $tKey If IsBinary($kKey) Then $iKeyLen = BinaryLen($kKey) $tKey = DllStructCreate("byte[" & $iKeyLen & "]") DllStructSetData($tKey, 1, $kKey) Else $tKey = __SQLite_StringToUtf8Struct(String($kKey)) If @error Then Return SetError(2, @error, -1) $iKeyLen = DllStructGetSize($tKey) - 1 ; don't count the terminating \0 EndIf ConsoleWrite("dll called with key = >" & DllStructGetData($tKey, 1) & "< and length = " & $iKeyLen & @LF) Local $avRval = DllCall($g_hDll_SQLite, "int:cdecl", "sqlite3_key", "ptr", $hDB, "ptr", DllStructGetPtr($tKey), "int", $iKeyLen) If @error Then Return SetError(1, @error, 0) ; Dllcall error If $avRval[0] <> $SQLITE_OK Then SetError(3, $avRval[0], -1) Return($SQLITE_OK) EndFunc ;==>_SQLite_Key ; #FUNCTION# ==================================================================================================================== ; Name...........: _SQLite_ReKey ; Description ...: Specify a new cryptographic key for a given Database (if you use system.data.sqlite.dll) ; Syntax.........: _SQLite_ReKey($hDB [, $kKey]) ; Parameters ....: $hDB - An Open Database, Use -1 to use Last Opened Database ; $kKey - Optional, new key to be used, passed as a string or a binary variant ; By default, the database will be "encrypted" with a null key, that is it will be unencrypted, ; making it useable by the standard version of sqlite3.dll ; Return values .: On Success - Returns $SQLITE_OK ; @error Value(s): -1 - SQLite Reported an Error (Check @extended Value) ; 1 - Library misuse (sqlite DLL not loaded or wrong DB handle) ; 2 - Error while converting key string to UTF-8 ; 3 - Error Calling SQLite API 'sqlite3_rekey' ; @extended Value(s): Can be compared against $SQLITE_* Constants ; Author ........: jchd ; Remarks .......: this call won't work with the standard version of sqlite3.dll which doesn't support encryption. ; Alternative libraries like system.data.sqlite _do_ support encryption and will work with this function. ; As a safety measure you should perform an integrity check before changing the encryption key!!! ; =============================================================================================================================== Func _SQLite_ReKey($hDB, $kNewKey = Default) If Not $g_hDll_SQLite Then Return SetError(1, $SQLITE_MISUSE, -1) If __SQLite_hChk($hDB, 2) Then Return SetError(1, $SQLITE_MISUSE, -1) Local $iKeyLen, $tKey, $pPtr If Not IsKeyword($kNewKey) Then If IsBinary($kNewKey) Then $iKeyLen = BinaryLen($kNewKey) $tKey = DllStructCreate("byte[" & $iKeyLen & "]") DllStructSetData($tKey, 1, $kNewKey) Else $tKey = __SQLite_StringToUtf8Struct(String($kNewKey)) If @error Then Return SetError(2, @error, -1) $iKeyLen = DllStructGetSize($tKey) - 1 ; don't count the terminating \0 EndIf $pPtr = DllStructGetPtr($tKey) Else $pPtr = 0 $iKeyLen = 0 EndIf Local $avRval = DllCall($g_hDll_SQLite, "int:cdecl", "sqlite3_rekey", "ptr", $hDB, "ptr", $pPtr, "int", $iKeyLen) If @error Then Return SetError(1, @error, 0) ; Dllcall error If $avRval[0] <> $SQLITE_OK Then SetError(3, $avRval[0], -1) Return($SQLITE_OK) EndFunc ;==>_SQLite_ReKey EDIT: code changed to tested working version1 point
-
@StungStang: Here you are. -use Open to open the db -then encrpypt it using ReKey -now encrypted is set up next time using the db: -open using Open -use Key to specify key [-use ReKey to chage key / remove key) Func _SQLite_Key($hDB, $bKey) ; ProgAndy If __SQLite_hChk($hDB, $SQLITE_ERROR) = $SQLITE_ERROR Then Return SetError(-1, 0, $SQLITE_ERROR) $bKey = Binary($bKey) Local $iLen = BinaryLen($bKey) Local $tKey = DllStructCreate("byte[" & $iLen & "]") DllStructSetData($tKey, 1, $bKey) Local $avRval = DllCall($g_hDll_SQLite, "int:cdecl", "sqlite3_key", "ptr", $hDB, "ptr", DllStructGetPtr($tKey), "int", $iLen) If @error Then Return SetError(-1, 0, $SQLITE_ERROR) Return $avRval[0] EndFunc Func _SQLite_ReKey($hDB, $bKey) ; ProgAndy If __SQLite_hChk($hDB, $SQLITE_ERROR) = $SQLITE_ERROR Then Return SetError(-1, 0, $SQLITE_ERROR) $bKey = Binary($bKey) Local $iLen = BinaryLen($bKey) Local $tKey = DllStructCreate("byte[" & $iLen & "]") DllStructSetData($tKey, 1, $bKey) Local $avRval = DllCall($g_hDll_SQLite, "int:cdecl", "sqlite3_rekey", "ptr", $hDB, "ptr", DllStructGetPtr($tKey), "int", $iLen) If @error Then Return SetError(-1, 0, $SQLITE_ERROR) Return $avRval[0] EndFunc1 point