BCX v8.2.6 is available for download

Started by MrBcx, March 21, 2025, 09:25:53 AM

Previous topic - Next topic

Quin

I run away for the weekend and you go and make an entire new BCX release! :D thanks as always for all your great work, MrBcx, going to now spend the next couple hours playing with this rather than sleeping. :)

MrBcx

Quote from: Vortex on March 21, 2025, 04:12:17 PMHi Kevin,

This one works without any issues :

DIM AnyType[3] AS INT_PTR
AnyType[0] = (INT_PTR) "This is %s %u."
AnyType[1] = (INT_PTR) "test"
AnyType[2] = (INT_PTR) 1
BCX_DYNACALL("msvcrt", "printf", 3, AnyType)

PRINT "All should be OK."

No need of the inline assembly code balancing the stack.

I suppose that's good to know but testing other functions that reside within
msvcrt.dll seems like a prudent thing to do before jumping in head first.



Vortex

Hi Kevin,

This one works without any issues :

DIM AnyType[3] AS INT_PTR
AnyType[0] = (INT_PTR) "This is %s %u."
AnyType[1] = (INT_PTR) "test"
AnyType[2] = (INT_PTR) 1
BCX_DYNACALL("msvcrt", "printf", 3, AnyType)

PRINT "All should be OK."

No need of the inline assembly code balancing the stack.

MrBcx

#3
My enhancements are intended for accessing WinApi functions and similar using WINAPI (_stdcall) convention. 

The new runtimes accomplishe their work in a similar manner as when using the DECLARE statement but without
BCX needing to create individual typedefs for every function that we invoke dynamically.  That's also why the runtimes
don't need to differentiate the complex x64 calling convention vs _stdcall calling convention when compiling to 64-bit.

If one really needs to use the c-calling convention, the C_DECLARE statement will enable that.

Or it could be coded using inline c.


Vortex

#2
Hi Kevin,

Thanks for the new release. Let's assume that BCX_DYNACALL calls a C function. It's the caller's responsibility to balance the stack after calling a C function. Maybe, you could add a new function like BCX_DYNACALL_C for this purpose.

A quick example :

DIM AnyType[3] AS INT_PTR
AnyType[0] = (INT_PTR) "This is %s %u."
AnyType[1] = (INT_PTR) "test"
AnyType[2] = (INT_PTR) 1
BCX_DYNACALL("msvcrt", "printf", 3, AnyType)

$CCODE
 __asm
{
    add esp, 3*4
}
$CCODE

PRINT "All should be OK."

The code will crash as the stack is unbalanced after returning back from BCX_DynaCall :

        mov    eax, offset @1357
        mov    dword ptr [_AnyType+4H], eax
        mov    dword ptr [_AnyType+8H], 1
        push    offset _AnyType
        push    3             
        push    offset @1359 
        push    offset @1358 
        call    _BCX_DynaCallA
        add    esp, 16  <--- This line       
        add    esp, 12  <--- and this line

MrBcx

#1
BCX 8.2.6 has been uploaded.

This update includes bug fixes and new features.

https://bcxbasiccoders.com/archives/YahooGroups/Bcx_Files_New/Bcx826.zip

SHA-256
b88e40e3e74ea2e7aa5b0ca1f176566a48f658ee4e35fe6793725c0a0627fb47
REVISIONS

*********************************************************************************************
2025/03/21       Changes in 8.2.6 from 8.2.5
*********************************************************************************************
Kevin Diggins  : Enhanced BCX_DYNACALL and LIB to compile with 64-bit and 32-bit executables.
                 All inline assembly has been replaced with pure C code and directives for
                 maximum compatibility with all popular Windows c/c++ compilers.
                 Both commands are limited to functions with no more than 16 arguments which
                 should be more than enough for any rationally designed function.  These
                 enhancements are mostly backward-compatible with existing BCX code.

Kevin Diggins  : The LIB statement can now be used in 64-bit and 32-bit executables.
                 FOR example, this one line of code will popup a Windows MessageBox:
                 MessageBox(LIB "user32", NULL, "Your Msg", "Your Title", MB_OK)
                 -----------^^^

Kevin Diggins  : BCX_DYNACALL() can now be used in 64-bit and 32-bit executables.
                 BCXHelp has the following example which only compiles with 32-bit:

                 DIM AnyType[4] AS INT
                 AnyType[0] = (INT) NULL
                 AnyType[1] = (INT) "Your Title"
                 AnyType[2] = (INT) "Your Msg"
                 AnyType[3] = (INT) MB_OK
                 BCX_DYNACALL("user32", "MessageBox", 4, AnyType)

                 When we replace INT with INT_PTR, it compiles in 32-bit and 64-bit.

                 DIM AnyType[4] AS INT_PTR    ' INT_PTR works for 32-bit and 64-bit executables
                 AnyType[0] = (INT_PTR) NULL
                 AnyType[1] = (INT_PTR) "Your Title"
                 AnyType[2] = (INT_PTR) "Your Msg"
                 AnyType[3] = (INT_PTR) MB_OK
                 BCX_DYNACALL("user32", "MessageBox", 4, AnyType)

Kevin Diggins  : Fixed "Me" keyword bug introduced during 8.2.5 WITH/ENDWITH refinements.

Kevin Diggins  : Refined the translation of WITH/ENDWITH statements (This might nail it!)

Kevin Diggins  : The 8.2.5 limitation involving the statement separator (:) and the string
                 concatenation operator (+=) has been removed. This means that BCX can now
                 correctly translate lines containing multiple statements.  For Example:
                         DIM A$ : A$ += "Yippie!" : PRINT A$ : PAUSE

Kevin Diggins  : Small enhancement to the USING$() function.  Zeros can now be used inside
                 the format string to LEFT pad the resulting string with zeros. Commonly
                 useful for formatting time and date strings but not limited to those.
                 SOME EXAMPLES:
                 
                 PRINT USING$("###.##", PI)        ' Normal, no LEFT padding occurs
                 PRINT USING$("  #.####", PI)      ' Explicit LEFT padding (spaces) 
                 PRINT USING$("000.000000", PI)    ' Pad 2 zeros on LEFT side of PI
                 PRINT USING$("0000.########", PI) ' Pad 3 zeros on LEFT side of PI

                 OUTPUT:

                 3.14
                   3.1416
                 003.141593
                 0003.14159265         

Kevin Diggins  : Replaced > internal < BCX function IsNumber() with IsNumberEx(), renaming
                 IsNumberEx() to IsDecimalNumber() and included more detections that
                 strengthen the reliabilty of IsDecimalNumber() and IsHexNumber() functions.

Kevin Diggins  : Added Intel C++ compiler detection

Kevin Diggins  : WS_TABSTOP added to 5 BCX GUI controls that lacked it, per Quin's request.

Kevin Diggins  : Ongoing formatting improvements to the source, output and runtime code