Leaderboard
Popular Content
Showing content with the highest reputation on 03/28/2022 in all areas
-
Return a string from a dll ?
pixelsearch reacted to Andreik for a topic
Why not simple like this? PS: maybe with some checks to prevent the overflows #include <windows.h> extern "C" { __declspec (dllexport) void change(char str[]) { strcpy(str, "This is my new string."); } } int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved) { return 1; } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { return 0; }1 point -
WebDriver UDF - Help & Support (III)
seadoggie01 reacted to Danp2 for a topic
Latest update just released. See below for change log.1 point -
Return a string from a dll ?
pixelsearch reacted to jchd for a topic
AutoIt uses Variants to hold your data, which isn't the form a C/C++ vanilla DLL expects. Fixed-size data (e.g. numeric values) cause no issue, but strings are a problem in this context, being variable-sized. DllCall does a lot of conversions in/out under your feet to insure the callee doesn't destroy AutoIt workspace memory.1 point -
There is multiple ways to skin this particular cat (proverbial expression on AutoIt forum ). Here one of them - clean - simple : #include <GUIConstants.au3> Example() Func Example() GUICreate("Test", 225, 80) Local $idF4 = GUICtrlCreateDummy() Local $idF5 = GUICtrlCreateDummy() Local $idExit = GUICtrlCreateButton("Exit", 150, 50, 65, 25) Local $aAccelKeys[2][2] = [["{F4}", $idF4], ["{F5}", $idF5]] GUISetAccelerators($aAccelKeys) GUISetState(@SW_SHOW) ; Display the GUI. While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idExit ExitLoop Case $idF4 ConsoleWrite("F4 was pressed" & @CRLF) Case $idF5 ConsoleWrite("F5 was pressed" & @CRLF) EndSwitch WEnd EndFunc ;==>Example1 point
-
How To Convert DLLs into an AutoIT UDF?
noellarkin reacted to RTFC for a topic
Actiona has an open-source C++ GitHub repository, so in theory it's possible to do what you want, provided: you are sufficiently competent in C++ (your AutoIt skills are almost irrelevant in this respect) and comfortable with MSVC or similar compiler environment the source is adequately documented (doesn't look like it) and modular (so the image-procesing part can be extracted easily; haven't checked this), C++ can be written in a variety of styles (heavily OOP or not, multi-threaded or not, integrated with other language-based components or not, template-library based or not, etc) Writing a c++ dll from scratch to integrate with AutoIt is fairly easy (example), but adapting someone else's existing code to function as a dll won't be, unless the original is already set up to be library/dll-based (if so, you'd just have to extract the required parts and write a wrapper library for it in AutoIt). The main problem I suspect will be the external parts your desired internal functions will rely on (the back-end of the back-end, if you will) which may be impossible/difficult to port to an AutoIt environment. My advice: investigate other image-processing options (existing AutoIt UDFs and/or dll's) rather than spending ages trying to analyse whether all hidden dependencies are actually portable/extractable. In most cases, there are plenty of alternative ways to skin any particular cat.1 point -
_Excel_RangeRead How to read all cells in a single column
noellarkin reacted to water for a topic
A $ is missing, should be: $Array = _Excel_RangeRead($ExcelWorkBook, $Sheet, $ExcelWorkBook.Worksheets($Sheet).Usedrange.Columns("A:A"), 1)1 point -
I am very glad to say that I found the reason: a debug DLL is not supposed to run without Visual Studio. So here I attach the release builds of both DLLs, they are tested with a new machine, and the size is much smaller. 😄 NewHook.zip1 point
-
_Excel_RangeRead How to read all cells in a single column
noellarkin reacted to Danp2 for a topic
Ok... Then something like this should work -- $Array = _Excel_RangeRead($ExcelWorkBook, $Sheet, $ExcelWorkBook.worksheets($Sheet).Usedrange.Columns("A:A"), 1)1 point -
what do you get if you put the following line in your script? MsgBox(0, '', EnvGet('username') & @TAB & @UserName) Are the two usernames the same?1 point
-
Can you try this if it works properly: Func Measure($sString, $iW, $iH, $sFont = "Arial", $iStyle = 0, $iFormat = 0) Local Const $hFormat = _GDIPlus_StringFormatCreate($iFormat) Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $iFontSize = 4 Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iStyle) Local Const $hGraphics = _GDIPlus_GraphicsCreateFromHDC(_WinAPI_GetWindowDC(0)) Local $tLayout = _GDIPlus_RectFCreate() Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphics) Local $fWidth = $iFontSize * $aInfo[0].width, $fHeight = $iFontSize * $aInfo[0].height If $fWidth < $iW And $fHeight < $iH Then If $iW > $iH Then Return $iFontSize * $iH / $aInfo[0].height Return $iFontSize * $iW / $aInfo[0].width ElseIf $fWidth > $iW And $fHeight < $iH Then Return $iFontSize * $iW / $aInfo[0].width Else If $fWidth < $fHeight Then Return $iFontSize * $iW / $aInfo[0].width If $iH > $iW Then Return $iFontSize * $iW / $aInfo[0].width Return $iFontSize * $iH / $aInfo[0].height EndIf EndFunc1 point
-
Thanks UEZ it's a clean script but it doesn't work for any random string. Just comment the last 5 lines of $sString and see what I mean. EDIT: I modified a little bit your script to ensure the visibility of the longest line also and seems to work good #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $sString, $iFontSize Local $iW = @DesktopWidth / 4, $iH = @DesktopHeight / 4 $hGUI = GUICreate("GDI+", $iW, $iH) ;, 0, 0, 0x80000000) GUISetState(@SW_SHOW) $sString = 'Take this kiss upon the brow!' & @CRLF $sString &= 'And, in parting from you now,' & @CRLF $sString &= 'Thus much let me avow--' & @CRLF $sString &= 'You are not wrong, who deem' & @CRLF $sString &= 'That my days have been a dream;' & @CRLF $sString &= 'Yet if hope has flown away' & @CRLF $sString &= 'In a night, or in a day,' & @CRLF $sString &= 'In a vision, or in none,' & @CRLF $sString &= 'Is it therefore the less gone?' & @CRLF $sString &= 'All that we see or seem' & @CRLF $sString &= 'Is but a dream within a dream.' _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $hFormat = _GDIPlus_StringFormatCreate(0x1000) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) $hFamily = _GDIPlus_FontFamilyCreate("Arial") $tLayout = _GDIPlus_RectFCreate(20, 20, $iW - 40, $iH - 40) $iFontSize = Measure($sString, $iW - 40, $iH - 40) $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize) ; <<< Adjust font size _GDIPlus_GraphicsClear($hGraphic) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $tLayout, $hFormat, $hBrush) $hPen = _GDIPlus_PenCreate(0xFF00F000) _GDIPlus_GraphicsDrawRect($hGraphic, $tLayout.x, $tLayout.y, $tLayout.width, $tLayout.height, $hPen) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_PenDispose($hPen) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Func Measure($sString, $iW, $iH, $sFont = "Arial", $iStyle = 0) Local $LongestLine Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $iFontSize = 4 Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iStyle) Local Const $hGraphics = _GDIPlus_GraphicsCreateFromHDC(_WinAPI_GetWindowDC(0)) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) Local $aLines = StringSplit($sString, @CRLF, 1) For $Index = 1 To $aLines[0] $LongestLine = StringLen($LongestLine) > StringLen($aLines[$Index]) ? $LongestLine : $aLines[$Index] Next Local Const $aInfo1 = _GDIPlus_GraphicsMeasureString($hGraphics, $LongestLine, $hFont, $tLayout, $hFormat) Local $iSizeW = $iFontSize * $iW / $aInfo1[0].width Local Const $aInfo2 = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat) Local $iSizeH = $iFontSize * $iH / $aInfo2[0].height _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphics) Return $iSizeW > $iSizeH ? $iSizeH : $iSizeW EndFunc1 point
-
Try this: #include <GDIPlus.au3> #include <GUIConstantsEx.au3> Local $hGUI, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $sString, $iFontSize Local $iW = @DesktopWidth / 4, $iH = @DesktopHeight / 4 $hGUI = GUICreate("GDI+", $iW, $iH) ;, 0, 0, 0x80000000) GUISetState(@SW_SHOW) $sString = 'Take this kiss upon the brow!' & @CRLF $sString &= 'And, in parting from you now,' & @CRLF $sString &= 'Thus much let me avow--' & @CRLF $sString &= 'You are not wrong, who deem' & @CRLF $sString &= 'That my days have been a dream;' & @CRLF $sString &= 'Yet if hope has flown away' & @CRLF $sString &= 'In a night, or in a day,' & @CRLF $sString &= 'In a vision, or in none,' & @CRLF $sString &= 'Is it therefore the less gone?' & @CRLF $sString &= 'All that we see or seem' & @CRLF $sString &= 'Is but a dream within a dream.' _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $hFormat = _GDIPlus_StringFormatCreate(0x1000) _GDIPlus_StringFormatSetAlign($hFormat, 1) _GDIPlus_StringFormatSetLineAlign($hFormat, 1) $hFamily = _GDIPlus_FontFamilyCreate("Arial") $tLayout = _GDIPlus_RectFCreate(20, 20, $iW - 40, $iH - 40) $iFontSize = Measure($sString, $iW - 40, $iH - 40) $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize ) ; <<< Adjust font size _GDIPlus_GraphicsClear($hGraphic) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sString, $hFont, $tLayout, $hFormat, $hBrush) $hPen = _GDIPlus_PenCreate(0xFF00F000) _GDIPlus_GraphicsDrawRect($hGraphic, $tLayout.x, $tLayout.y, $tLayout.width, $tLayout.height, $hPen) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GDIPlus_PenDispose($hPen) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Func Measure($sString, $iW, $iH, $sFont = "Arial", $iStyle = 0) Local Const $hFormat = _GDIPlus_StringFormatCreate() Local Const $hFamily = _GDIPlus_FontFamilyCreate($sFont) Local Const $iFontSize = 4 Local Const $hFont = _GDIPlus_FontCreate($hFamily, $iFontSize, $iStyle) Local Const $hGraphics = _GDIPlus_GraphicsCreateFromHDC(_WinAPI_GetWindowDC(0)) Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH) Local Const $aInfo = _GDIPlus_GraphicsMeasureString($hGraphics, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_GraphicsDispose($hGraphics) If $iW > $iH Then Return $iFontSize * $iH / $aInfo[0].height Return $iFontSize * $iW / $aInfo[0].width EndFunc1 point
-
Just found out where this might apply! The _sql library that we use (from Chris Lambert) apparently brings in NULLS as "Default". I was trying to detect the NULL values using If $varName = "" Then ... EndIf Which was not working, so now I do If IsKeyword($varName) OR $varName = "" Then ... EndIf Which works as it should. Just thought I'd throw this note in here for anyone else using the _sql library and trying to detect empty (NULL) values.1 point
-
Thank you @UEZ that code show me exactly how to do it. I modify the code to use $aMeasure[1] - The number of characters that actually fit into the layout rectangle and use StringLen to know the number of characters. The final code base on your code is this one: #include <GDIPlus.au3> #include <String.au3> _GDIPlus_Startup() $sText = "Example very very long string then keep and keep and keep and keep writing until the font get reduced this is the way I need it" $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Clas1.jpg") $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage) $dimen = _GDIPlus_ImageGetDimension($hImage) $iTextLen = StringLen($sText) Local $hBrush = _GDIPlus_BrushCreateSolid(0xFF009900) Local $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local $hLayout = _GDIPlus_RectFCreate(0, $dimen[1] - 280, $dimen[0], $dimen[1] - ($dimen[1] - 280)) Local $hStringFormat = _GDIPlus_StringFormatCreate() $fSize = 50 Do $hFont = _GDIPlus_FontCreate($hFamily, $fSize) $aMeasure = _GDIPlus_GraphicsMeasureString($hGraphic, $sText, $hFont, $hLayout, $hStringFormat) If $aMeasure[1] = $iTextLen Then ExitLoop $fSize -= 1 _GDIPlus_FontDispose($hFont) Until False ConsoleWrite("Font size: " & $fSize & @CRLF) $fSize = $fSize - 5 $hFont = _GDIPlus_FontCreate($hFamily, $fSize) _GDIPlus_GraphicsDrawStringEx($hGraphic, $sText , $hFont, $hLayout, $hStringFormat, $hBrush) _GDIPlus_ImageSaveToFile($hImage, @ScriptDir & "\GDIPlus_ImageWithText.jpg") ; Clean up resources _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hImage) _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_Shutdown() ShellExecute(@ScriptDir & "\GDIPlus_ImageWithText.jpg") Regards Alien.1 point