Problem making a Dialog Box

For other topics related to the FreeBASIC project or its community.
MrSwiss
Posts: 3307
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Problem making a Dialog Box

Postby MrSwiss » Apr 24, 2017 9:37

Josep Roca wrote:INT_PTR is defined as a longint in the Windows headers (basetsd.bi).
This is a WIN-API extension, not FB (language) native! = LongInt (Ptr, probably)
(you can also *define* it, as: Josep_Roca_INT64, if you like, in another header!)
You guys from PB, are just too much married, to WIN-API ... (FB is multi OS!!).
St_W
Posts: 1478
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Problem making a Dialog Box

Postby St_W » Apr 24, 2017 10:59

MrSwiss wrote:This is a WIN-API extension, not FB (language) native! [...] (FB is multi OS!!).
Yes, INT_PTR not FB-native and Yes, FB supports multiple operating systems ... BUT ... if one decides to use the Win32-API and e.g. uses the "DialogBoxIndirect" function defined as "INT_PTR WINAPI DialogBoxIndirect( ... )" one should use "INT_PTR" for the return value and not some other data type, no matter whether it will be equivalent or not.
So please stop criticising FB users for using the Win32-API and its data types over and over again (this hasn't been the first time you're doing that). It is perfectly fine to use the Win32-API if the programmer is aware that this will limit the application to Windows, so please accept that or at least don't try to force your personal opinion on them.

Sorry for the off-topic post, but I thought that had to be said. I don't want our new FB users being frightened away because of some baseless accusations.
MrSwiss
Posts: 3307
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Problem making a Dialog Box

Postby MrSwiss » Apr 24, 2017 11:39

@St_w,

St_W wrote:Yes, INT_PTR not FB-native and Yes, FB supports multiple operating systems <-- no but's needed
Just stop you're unfounded allegations.
You don't hold the monopoly, to express opinion, advice, sentiments, ideas etc.
Repeating oneself: you've just done it, again ...
Josep Roca
Posts: 449
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Problem making a Dialog Box

Postby Josep Roca » Apr 24, 2017 14:08

MrSwiss wrote:
Josep Roca wrote:INT_PTR is defined as a longint in the Windows headers (basetsd.bi).
This is a WIN-API extension, not FB (language) native! = LongInt (Ptr, probably)
(you can also *define* it, as: Josep_Roca_INT64, if you like, in another header!)
You guys from PB, are just too much married, to WIN-API ... (FB is multi OS!!).


To be correct, INT_PTR evaluates as a long with 32 bit and as a longint with 64 bit. And not, despite its name, it is not a pointer.

I have not written the Windows API headers for FB. Maybe you should have asked his author to only use FB native data types, instead of so many aliases, to please you. But I'm afraid that it is too late.

I know that FB is cross-platform, but I only program with Windows, and I have come here looking for a BASIC compiler able to compile for Windows 32 and 64 bit.
Josep Roca
Posts: 449
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Problem making a Dialog Box

Postby Josep Roca » Apr 24, 2017 14:10

dodicat wrote:Hi Josep Roca.
Your code works with 64 bit, and 32 bit -gen gcc.
But not -gen gas. (No dialog box visible)
Win 10.


Weird. It works fine with Windows 7. Perhaps there is a problem with the code generated by gas in Windows 10?
SARG
Posts: 910
Joined: May 27, 2005 7:15
Location: FRANCE

Re: Problem making a Dialog Box

Postby SARG » Apr 24, 2017 14:17

dodicat wrote:Your code works with 64 bit, and 32 bit -gen gcc.
But not -gen gas. (No dialog box visible)
Win 10.

The issue with -gen gas : in some cases the memory after the DLGTEMPLATE structure is not zero initialised, due to alignment.
In these cases the API function gets invalid data.... If lucky there are zeroes.
Using getlasterror to get the extended error message and fbdebugger to see the memory values.
I check poking zero just after the DLGTEMPLATE structure that works well but not safe.
*(Cast(UShort Ptr,lpdt)+(SizeOf(DLGTEMPLATE)\SizeOf(UShort)))=0

The best solution : a zeroed area, enough large.

Code: Select all

function NewDialog( byval hParent as HWND, byval lpDialogProc as DLGPROC) as INT_PTR
                             
 Dim as long rval
 Dim strTitle as string
 
 Dim lpdt As DLGTEMPLATE Ptr = CAllocate(1, SizeOf(DLGTEMPLATE)+12)
 
  lpdt->style = WS_OVERLAPPEDWINDOW            'DS_MODALFRAME OR DS_CENTER OR WS_VISIBLE OR WS_OVERLAPPEDWINDOW
  lpdt->dwExtendedStyle = 0
  lpdt->cx = 170
  lpdt->cy = 200
  lpdt->cdit = 0
  lpdt->x = 50
  lpdt->y = 50

  rval = DialogBoxIndirect(GetModuleHandle(null),lpdt,hParent,lpDialogProc)
  DeAllocate lpdt
  return rval

end function
dkl
Site Admin
Posts: 3210
Joined: Jul 28, 2005 14:45
Location: Germany

Re: Problem making a Dialog Box

Postby dkl » Apr 24, 2017 17:53

Hmm, I looked at the DialogBoxIndirect() documentation and it says that it wants a header ... followed by one or more additional blocks of data. So apparently having just the DLGTEMPLATE is not enough and will lead to a buffer overflow.
James Klutho
Posts: 14
Joined: Nov 11, 2009 23:44

Re: Problem making a Dialog Box

Postby James Klutho » Apr 24, 2017 18:35

@ SARG

Wow - that did the trick - the CAllocate is what I needed. After dkl comments, I increased the safety bytes from 12 to 300. It seems to compile reliably in 32 bit and 64 bit now.

@Everyone who suggested something

Thanks to everyone for their input. I could not have done it without you. I tried everyone's suggestions but to no avail. I got some suggestions to work for a compile or two but then it would not work. I was so frustrated.

Thanks again
Jim

Return to “Community Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest