Author Topic: (DLGPROC)(DLGPROC)(DLGPROC)  (Read 627 times)

Robert

  • Hero Member
  • *****
  • Posts: 1237
    • View Profile
(DLGPROC)(DLGPROC)(DLGPROC)
« on: November 20, 2023, 01:46:55 PM »
Hi MrBCX:

In this 

Code: [Select]
$BCXVERSION "7.1.8"
 
 GLOBAL hEdit1   AS HWND
 GLOBAL hButton1 AS HWND
 GLOBAL hButton2 AS HWND
 GLOBAL hStatic1 AS HWND
 
 FUNCTION WINMAIN()
   FUNCTION = BCX_MDIALOG((DLGPROC)InputBox,"InputBox App", _
                   0, 157, 76, 146, 61, 0, 0, "TAHOMA", 16)
 END FUNCTION
 
 BEGIN MODAL DIALOG AS InputBox
   LOCAL Txt$
   SELECT CASE Msg
 
     CASE WM_INITDIALOG
     hEdit1 = BCX_EDIT("BCX is cool!", hWnd, 101, 3, 6, 69, 30)
     hButton1 = BCX_BUTTON("Okay", hWnd, 102, 4, 43, 40, 14)
     hButton2 = BCX_BUTTON("Cancel", hWnd, 104, 100, 43, 40, 14)
     hStatic1 = BCX_LABEL(" ", hWnd, 103, 78, 6, 64, 30)
     BCX_SET_FONT(hStatic1, "TAHOMA", 12) 'for comparison
    CENTER(hWnd)
 
     CASE WM_COMMAND
     IF CBCTLMSG = BN_CLICKED THEN
       IF CBCTL = 102 THEN 'clicked the okay button
        Txt$ = BCX_GET_TEXT$(hEdit1)
         BCX_SET_TEXT(hStatic1, Txt$)
       END IF
       IF CBCTL = 104 THEN 'clicked the cancel button
        CLOSEDIALOG
       END IF
     END IF
   END SELECT
 END DIALOG

this

Code: [Select]
FUNCTION WINMAIN()
   FUNCTION = BCX_MDIALOG((DLGPROC)InputBox(D[code],"InputBox App", _
                   0, 157, 76, 146, 61, 0, 0, "TAHOMA", 16)
 END FUNCTION

is translated to this

Code: [Select]
int WINAPI WinMain (HINSTANCE hInst,HINSTANCE hPrev,LPSTR CmdLine,int CmdShow)
{
  BCX_hInstance = hInst;
  return BCX_MDialog ((DLGPROC)(DLGPROC)(DLGPROC)InputBox,"InputBox App",0,157,76,146,61,0,0,"TAHOMA",16);
}

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2229
    • View Profile
Re: (DLGPROC)(DLGPROC)(DLGPROC)
« Reply #1 on: November 20, 2023, 04:07:49 PM »
Hi Robert,

The cast is automatically added by BCX.  I added that a couple years ago, IIRC,
but apparently failed to note it in the Revisions.txt.

Below is the salient bit from inside BC.bas

Code: [Select]
   CASE "bcx_mdialog"
                IF InWinMain AND NOT Use_BCXMDialog THEN
                    FPRINT Outfile, Scoot$, "BCX_hInstance = hInst;"
                    iEmitVarGroup = iEmitVarGroup BOR (eFontGroup BOR eBCX_hInstance)
                END IF
                Stk$[Tmp] = "BCX_MDialog"
                Stk$[Tmp+1] = "((DLGPROC)"
                Use_BCXDialogCommon = Use_BCXMDialog = Use_Proto = TRUE

            CASE "bcx_dialog"
                Stk$[Tmp] = "BCX_Dialog"
                Stk$[Tmp+1] = "((DLGPROC)"
                Use_BCXDialogCommon = Use_BCXDialog = Use_Proto = TRUE
« Last Edit: November 20, 2023, 05:20:58 PM by MrBcx »

Robert

  • Hero Member
  • *****
  • Posts: 1237
    • View Profile
Re: (DLGPROC)(DLGPROC)(DLGPROC)
« Reply #2 on: November 20, 2023, 06:09:27 PM »
Yes but why 3 casts ?

return BCX_MDialog ((DLGPROC)(DLGPROC)(DLGPROC)InputBox,"InputBox App",0,157,76,146,61,0,0,"TAHOMA",16);
}

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2229
    • View Profile
Re: (DLGPROC)(DLGPROC)(DLGPROC)
« Reply #3 on: November 20, 2023, 06:26:45 PM »
Thanks - I see now ... removing the cast in the example results in 2 casts being emitted
by BCX.  And not removing the cast results in 3, as you noted.  My first hunch as to why, is that
the bug is caused by a multi-pass issue.  Whatever is causing it, I'll fix it. 

[ADDED LATER]
I found it.
The updated handlers now get an additional test:  IF Tmp = 3 ...

Code: [Select]
CASE "bcx_mdialog"
IF InWinMain AND NOT Use_BCXMDialog THEN
FPRINT Outfile, Scoot$, "BCX_hInstance = hInst;"
iEmitVarGroup = iEmitVarGroup BOR (eFontGroup BOR eBCX_hInstance)
END IF
Stk$[Tmp] = "BCX_MDialog"
IF Tmp = 3 THEN Stk$[Tmp+1] = "((DLGPROC)"
Use_BCXDialogCommon = Use_BCXMDialog = Use_Proto = TRUE

CASE "bcx_dialog"
Stk$[Tmp] = "BCX_Dialog"
IF Tmp = 3 THEN Stk$[Tmp+1] = "((DLGPROC)"
Use_BCXDialogCommon = Use_BCXDialog = Use_Proto = TRUE

The example needs the cast removed because BCX emits it automatically.
« Last Edit: November 20, 2023, 07:37:47 PM by MrBcx »