Skip to content

FreeBasic v1.10.1 and AutoItX v3.3.16.1: Function return value changes depending on compilation command line #461

@Modzho

Description

@Modzho
' EXAMPLE TESTED ON:
' WINDOWS 11 Pro 25H2
' FreeBASIC Compiler - Version 1.10.1 (2023-12-24), built for win64 (64bit)
' (FreeBASIC-1.10.1-winlibs-gcc-9.3.0.7z)

' AutoItX v3.3.16.1

' AutoItX Library and FreeBasic Header file:
' https://mega.nz/file/P3YXXRBS#i7TN1Fp7TJWPZN8a_mtrothU6XT4zm0YYL7sEAkQ9A0
' https://www.freebasic.net/forum/viewtopic.php?t=33372

#Include "AutoItX3_DLL.bi"
#Inclib "AutoItX3_x64_DLL"

Dim As WString * 50 winTitle, result
Dim As String Calculator, message

' Launch Calculator
Calculator = "calc.exe"
AU3_Run(Calculator, NULL, 1)
AU3_Sleep(1000)

winTitle = "Kalkulators" ' Latvian; Edit as you need
'~ winTitle = "[CLASS:Calculator]"



'~ Do Stuff Here ...
' Send text to Calculator, Clipboard operations
message = "3,14" 'Uses a comma as the decimal separator due to Latvian
'                 regional settings (Windows 11 Pro 25H2); Edit as you need
message = "3,14*2="
AU3_ClipPut(message) ' Paste message into Clipboard
AU3_Sleep(1000)
AU3_Send("^v", 0) ' Paste into Calculator
AU3_Sleep(1000)
AU3_Send("^c", 0) ' Paste from Calculator into Clipboard
AU3_Sleep(1000)
AU3_ClipGet(result, 100) ' Write from Clipboard to result
Print "Pi from Calculator: "; result
AU3_Sleep(1000)
'~ END Stuff



' Close calc.exe
AU3_WinClose(winTitle, "") ' Comment out this line to test EXAMPLE with Calculator window exists
AU3_Sleep(1000) ' Wait 1 sec.

' Confirm closure

'~ Without "Stuff lines" all compile strings do work as expected
' from Autoitx chm help file: AU3_WinExists result in i = 0 window doesn't  exists, i = 1 window do exist


'~ With "Stuff lines" (Copy, Paste values in Calculator):
Dim i As Integer
i = AU3_WinExists(winTitle, "") ' COMPILED With fbc64.exe -w all "%f"
'                                 always returns 1, as if the window exists.
'                                 Even when Window is closed e.g. Window doesn't exist and must be 0.
'                                 IT IS WRONG

'                                 COMPILED With fbc64.exe -gen gcc -O 2 "%f"
'                                 returns 0 if Window doesn't exist and
'                                 returns 1 if Window exist
'                                 THAT IS CORRECT - AS EXPECTED                

If i = 0 Then ' = 0 means the window is not found.
    Print "Calculator closed successfully."
Elseif i = 1 Then
	Print "Calculator is running."
End If

Sleep

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions