Showing posts with label IDE Issues. Show all posts
Showing posts with label IDE Issues. Show all posts

01 October 2024

DEP and GB32

From MS:

"Data Execution Prevention (DEP) is a system-level memory protection feature that is built into the operating system starting with Windows XP and Windows Server 2003. DEP enables the system to mark one or more pages of memory as non-executable. Marking memory regions as non-executable means that code cannot be run from that region of memory, which makes it harder for the exploitation of buffer overruns."

I underlined the sentence that is important to GB32 developers. When a program is RUN (F5), the GB32 inline compiler creates an executable in memory and runs it from there. The DEP setting of your system can prevent the running of the code. This happened to a user who bought a new PC with a factory DEP setting of 3. Not only couldn't GB32 run the code, other nasty things happened as well, for instance programs couldn't be saved anymore.

To obtain the your system's DEP setting, you will need to follow the following steps:

  • Go to This PC -> right click and select Properties.Then select Advanced Settings and choose the Advanced tab, now click the Settings button of the Performance section. Here you can select the Data Execution Prevention tab. Normally, the option to protect Windows programs and services is selected. This conforms to DEP setting = 2.

You could also try this small GB32 program to obtain the system's DEP setting:

$Library "gfawinx"
$Library "UpdateRT"
UpdateRuntime ' Patches GfaWin23.Ocx
Declare Function GetSystemDEPPolicy Lib "kernel32" ()
Debug "DEP-Setting: "; GetSystemDEPPolicy()

The fact that you can Run the code tells you that the DEP setting isn't 3. A setting of 3 wouldn't allow the execution of the code stored in memory by the GB32 compiler.

It isn't a problem solely for the GB32 developer, but the final EXEs created with GB32 will also suffer from a DEP setting of 3. The EXE is a stand-alone program and its code can be executed, but the UpdateRuntime function 'hacks' the GfaWin23.ocx runtime and reroute some code to new code in memory, and executing new code in memory is not allowed with DEP = 3.

Conclusion
To be able to execute a GB32 produced EXE the DEP system setting of the user must be 2 or lower.

02 September 2021

The IDE’s Color Dialog

The IDE features a custom Color Dialog box to select the foreground and background colors for Ocx controls and Forms. The Color Dialog box is also used to select the editor’s syntax colors in the GB32’s Properties dialog box. Using the Color Dialog box you can select any color you want. However, the Color Dialog box presents a custom color palette for a quick selection. In addition the dialog box displays the system colors as they are defined on your version of Windows.

The Color Dialog box
The following picture displays the Color Dialog box after selecting the ForeColor property of a Form (frm1) in the form-editor. This dialog box will also be displayed after selecting the BackColor property.

Screenshot 2021年09月01日 ColorDlg

The ForeColor property shows a color value of 80000008,ドル which means that the color is set to the system color with index 8 (COLOR_WINDOWTEXT). The ForeColor property is used as the foreground color for drawing in the client area of the form.

The Color Dialog displays the 25 system colors in the lower two rows of the dialog box and it draws a focus rectangle around the color-cell that shows the system color for COLOR_WINDOWTEXT. The large cell at bottom-right of the dialog box displays the selected color. By clicking on the large box GB32 shows the common dialog’s color dialog box. The top 4 rows display a palette of often used RGB colors to allow a quick selection of a color. The fourth row also contains 8 additional colors otherwise not found in the 4 upper rows of the dialog’s color palette.

The BackColor property defines the color used to draw the (empty) contents of the client area. By default, GFA-BASIC 32 uses the system color COLOR_BTNFACE, the system color that is used to paint the shading of the face of command buttons. However, this system color is used for more UI-elements than just the shadow of the face of a button. By using the color-value 8000000ドルf the window background gets the default color of a dialog box, so that the GB32 form will look consistently with system dialog boxes.

Using system colors
It is a big advantage that GFA-BASIC 32 let you use system colors for the user-interface elements of the form and Ocx-controls. The system colors may change when a custom Windows theme is installed or when Microsoft changes the system colors with a new release of Windows. Whenever the system colors change, the colors of the form change accordingly, providing a consistent look with the OS.

GFA-BASIC 32 distinguishes between a pure RGB color format and a system color by setting the high-bit of the 32-bit color value (Long). When a Long value is displayed in it’s hexadecimal format the high-bit setting is shown as 80000000ドル. Before actually applying a color GB32 tests the high-bit of the color value and selects a system color when it is set:

If rgbcol %& 80000000ドル Then rgbcol = SysCol(rgbcol & $FF)

An application can specify a system color in two ways:

RGBColor 80000000ドル + COLOR_WINDOWFRAME
RGBColor SysCol(COLOR_WINDOWTEXT)

The first statement sets the foreground color to a system color value. The second statement converts the system color to an RGB-value beforehand. Both statements will eventually use the RGB color that belongs to the system’s color element COLOR_WINDOWTEXT. The RGB color value for any of the display elements is obtained using the GB32’s function SysCol or the API function GetSysColor(). Each aspect of the display has its own COLOR_* constant that is used as an index in these functions. These constants are built into GFA-BASIC 32. For more information see the SysCol function in the helpfile. It explains which constant represents what user-interface element. When you hoover over the system colors in the IDE Color Dialog box it shows a short description of the display element it represents.

The Editor colors
The Editor tab in the Properties dialog box (Extra | Properties) displays the same Color Dialog box to select the syntax colors.

Screenshot 2021年09月02日 ColorDlg

This picture is taken after clicking the BackColor button. It shows the selected color for the background of the “Changed/Empty” syntax (ie. the background color of empty lines and the line that is being edited). By default, the background color for all syntax elements is set to system color COLOR_WINDOW (80000005ドル). The foreground colors of the syntax elements are custom RGB values. By keeping the background color to a system color, the GFA-BASIC 32’s editor will adapt to the new COLOR_WINDOW color if a theme is installed.

27 August 2020

New features: my personal top 5

The past years GFA-BASIC 32 received some updates; bugs were fixed and new IDE features were added. If you checkout the readme25.rtf file that comes with the updates you might be overwhelmed by the number of (small) new features. To help you find your way I discuss my personal top 5 of the new IDE additions.

5 Print a Procedure
In a large program with many subroutines it is likely you want to print a single procedure rather than the entire program. To print the current subroutine – the one that contains the caret - choose the Procs button on the toolbar and select Print:

After selecting Print you will be presented the Windows Print dialog to select a printer and other options. Note that this is another fix, since the original GB only printed to the default printer.

4 Run As Exe
When developing a (new) program you should test the EXE version of the program on a regular basis. To make the process of compiling and testing a lot easier the toolbar offers the Run As Exe button. This button is enabled for a normal program and disabled when the editor contains a GLL or LG32. When you select the Run As Exe button the program is saved and compiled to exe. The first time you will be presented with the GFA-BASIC’s compile dialog box to specify the name and icon for the exe. If the program is compiled before and the exename is already specified the code is compiled with that name immediately and the dialog box is not shown. Also note that the dialog box contains a default icon for the exe.

When the compiling process did not generate any errors the EXE is executed directly. However, before executing the presence and version of of the GfaWin23.ocx runtime in the program’s directory is checked. In case there is a newer version of the runtime or if it is missing a message box will popup to inform you about the copying of the GfaWin23.ocx to the program’s directory. These days a DLL is no longer placed in the System32 directory, but accompanies the EXE in its own directory.

The new default icon for a GFA-BASIC standalone EXE contains 9 images to conform to the latest SDK requirements. A full set of icons includes images for 16x16, 32x32, 48x48, and 256x256. Windows selects the appropriate icon for the current DPI and Explorer View setting. The icons are taken from the multi-image app.ico file, which is located in the GFA-BASIC directory and is loaded when a program is compiled for the first time. The app.ico adds a resource of 41 KB to your program. Of course, a different .ico file can be loaded, but you should make sure to conform to UI-guidelines; an .ico format file of 766 Bytes is no longer the standard. Note - You can also use app2.ico (only 4 KB) from the GFA-BASIC directory which holds the same images but in a packed format. We did not encounter any problems with the packed version so far, so you could try it instead.

To support visual styles in your own programs the EXE must include a manifest file, either as a resource or as a stand-alone file. When Add Manifest Resource is checked the GfaWin32.exe.manifest is included as a resource after compiling automatically. The checkbox is only checked if the IDE is run with a manifest file. The checkbox setting isn’t stored in the program and is reset each time. To prevent the automatic inclusion of the manifest resource you should include the $ManifestOff directive in your code.

3 Insert miscellaneous text
Sometimes you want to store the program’s name and date into a comment line. By pressing App+I a popup menu appears that allow you to insert several kinds of information into the program’s code. These are the possible text items:

To easily insert the current procname into the code you can also use App+P. Inserting a procedure’s name is useful when displaying an error message box in a Try/Catch handler. The gfawinx function ErrMsg() is created with this feature in mind. ErrMsg returns the relevant properties of the Err-object in a single string ready to be displayed in a message box (see gfawinx.g32 in the Include directory for more info). The following picture shows when to press App+P to insert the proc’s name:

2 Grouping procedures
Actually this feature is my favorite, but I don’t use it as often as my number 1 favorite. To get a better overview of a large code file the procedures and functions can be grouped in collapsible groups. For this to happen a new editor command $Group has been implemented. To collect a series of procedures into a group add the $Group "title" statement just above a procedure in your code. As a result, the Procs tab in the sidebar will contain a collapsible group named “title” holding all procedures until the next $Group statement. A group can be removed by typing $GroupOff at the line with the $Group statement.

The picture above shows my grouping in the GfaWin32.gll program. Grouping allows me to collect related procedures into one section. It makes navigating the code very simple.
By right clicking in the Procs-tab listview you can fine tune the displaying of groups. For instance, the grouping can be (temporarily) disabled to display the procedures in the default manner. By default, groups outside the current the group are collapsed. This automatic collapsing of non-active groups can be disabled.

Hoovering over a procedure name (a Procs Listview-item) brings up a scrollable tooltip. The tooltip displays the code of that Proc. Use the mousewheel to show more or less lines. This also works in the editor. Hoover the mouse over a procedurename and Proc-PeekView pops up.

1 Edit history
My number one feature is Edit History, simply because I use it all the time without even realizing it. Edit History works in the background and saves the line last edited to the top of a stack. By using Esc or Ctrl+minus or the toolbar button < you are taken back to the lines you just edited. When stepping backwards, the steps are saved in a ‘forward stack’ so you can return easily to the last edited line using Ctrl+Shift+minus, or by clicking the appropriate > button in the toolbar.
The toolbar button for walking back has a collapsible menu that shows the line numbers and procnames you last edited. This way you can easily jump back to some line previously stored on the stack.

Subscribe to: Comments (Atom)

AltStyle によって変換されたページ (->オリジナル) /