Author Topic: Dialog as Main Window - Part 2  (Read 2967 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Dialog as Main Window - Part 2
« on: January 14, 2017, 07:57:00 AM »
Hello,

this is the way I created a stand-alone executable. I used the same rc file and code as in Part 1. The only difference is in Sliders.inc for loading the resources:
Code: OxygenBasic
  1. ...
  2. /*
  3. sys hResources = loadlibrary "Sliders.dll"
  4. if not hResources then
  5.   mbox "Error: Sliders.dll not found"
  6.   ExitProcess(1)
  7. end if
  8. */
  9.  
  10. sys hResources = hInstance
  11. ...
  12.  
To create the executable I used this batch file:
Code: [Select]
@echo off

set filename=Sliders

:: get path of Oxygenbasic
:: -------------------------
set o2_dir=c:\OxygenBasic
if not exist %o2_dir%\gxo2.exe goto missing_dir
if not exist %filename%.o2bas goto missing_file

:: delete exe, dll
::----------------
if exist %filename%.exe del %filename%.exe
if exist %filename%.dll del %filename%.dll

:: build main exe
::----------
echo gxo2: Building exe file
%o2_dir%\gxo2.exe %filename%.o2bas
cd res
if exist %filename%.rc %o2_dir%\tools\goRC %filename%.rc
cd ..
if exist res\%filename%.res %o2_dir%\tools\linkres2exe res\%filename%.res %filename%.exe

:: delete obj, res
::----------------
echo deleting obj, res files
if exist res\%filename%.obj del res\%filename%.obj
if exist res\%filename%.res del res\%filename%.res

::build or run main file
::-----------------------
echo Now Starting %filename%.exe
%filename%.exe
echo .
echo Done ...
goto goodbye


:missing_dir
echo.
echo Please correct the path for o2_dir in this batch file
echo.
pause
goto goodbye

:missing_file
echo.
echo Error:
echo missing %filename%.o2bas
echo .
pause

:goodbye

The purpose of this small project was to find a way to use the resources in a dll for developing the application and then as a last step create a stand-alone executable with the linked resources. The project and a 64-bit executable are attached as zip files.

The use of dialog based applications is limited in some ways. The Dlg2Src utilitiy of James would offer a more flexible option. But I think it is like always: the tool must be tested and applied a little bit more.

Roland


.

JRS

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #1 on: January 15, 2017, 06:33:06 PM »
I don't get BASIC translators like BaCon that generate un-maintainable C code. If your end goal is C then that is what you should be writing your code in. The guys on the BaCon forum spend most of their time with coming up with workarounds so BaCon can generate something useful.


JRS

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #2 on: January 17, 2017, 10:03:20 AM »
FreeBASIC also falls in the same category as BaCon generating non-human readable C code to stay in the game.

BCX/BC9/MBC is one of the few BASIC to C translators that generate expandable code at the C level.




Arnold

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #3 on: January 17, 2017, 11:47:12 AM »
Hi Mike,

there is good news. I suppose I understand a little bit more about the purpose of manifests. The bad news is that my app will not work any more the way I expected. Did it work for you? Must I really use InitCommonControlsEx (which would be my next step) or can I use InitCommonControls nevertheless?

I tried both ways: 1) using GoRc.exe + LinkRes2.exe with batch file, and  2) compiling .rc to res, compiling Sliders.o2bas and then added the .res file to Sliders.exe using Resource Hacker 4.5.30.

This is Sliders.rc
Code: [Select]
#define MANIFEST 24
#define IDD_DLGMain 1000
#define IDC_Toolbar 1001
#define IDC_Table 1002
#define IDR_MAINMENU 10000
#define IDM_StartGame 10001
#define IDM_Exit 10002
#define IDM_MATRIX3 10009
#define IDM_MATRIX4 10010
#define IDM_MATRIX5 10012
#define IDM_SOUND 10013
#define IDM_ABOUT 10016
#define IDI_AppIcon 100
#define ID_TBbmp 101
#define IDB_Color3 102
#define IDB_Color4 103
#define IDB_Color5 104
#define IDR_VERSION1 1

LANGUAGE 9,2

IDD_DLGMain DIALOGEX -2,-11,240,188
CAPTION "Slider Puzzles"
FONT 10,"MS Sans Serif",400,0,0
MENU IDR_MAINMENU
STYLE WS_VISIBLE|WS_OVERLAPPEDWINDOW|DS_CENTER
BEGIN
  CONTROL "",IDC_Toolbar,"ToolbarWindow32",WS_CHILDWINDOW|WS_VISIBLE|TBSTYLE_TOOLTIPS|CCS_TOP,0,0,42,12
  CONTROL "",IDC_Table,"Static",WS_CHILDWINDOW|WS_VISIBLE,42,24,154,154,WS_EX_CLIENTEDGE
END

IDR_MAINMENU MENU
BEGIN
  POPUP "&Game"
  BEGIN
    MENUITEM "&Start New Game\tF2",IDM_StartGame
    MENUITEM SEPARATOR
    MENUITEM "E&xit\tAlt+F4",IDM_Exit
  END
  POPUP "&Options"
  BEGIN
    POPUP "&Size Board"
    BEGIN
      MENUITEM "&3 x 3",IDM_MATRIX3,CHECKED
      MENUITEM "&4 x 4",IDM_MATRIX4
      MENUITEM "&5 x 5",IDM_MATRIX5
    END
    MENUITEM "&Sound\tCtrl+S",IDM_SOUND,CHECKED
  END
  POPUP "&Help"
  BEGIN
    MENUITEM "&About\tF1",IDM_ABOUT
  END
END

IDI_AppIcon ICON DISCARDABLE "Sliders.ico"
ID_TBbmp BITMAP DISCARDABLE "toolbar.bmp"
IDB_Color3 BITMAP DISCARDABLE "color3.bmp"
IDB_Color4 BITMAP DISCARDABLE "color4.bmp"
IDB_Color5 BITMAP DISCARDABLE "color5.bmp"

IDR_VERSION1 VERSIONINFO
FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x00000004
FILETYPE 0x00000001
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "08090000"
    BEGIN
      VALUE "FileVersion", "1.0.0.0\0"
      VALUE "ProductVersion", "1.0.0.0\0"
      VALUE "CompanyName", "OxygenBasic.org, http://www.OxygenBasic.org/\0"
      VALUE "ProductName", "Slider Puzzles\0"
      VALUE "FileDescription", "Slider Puzzle Game\0"
      VALUE "InternalName", "Sliders\0"
      VALUE "LegalCopyright", "Public Domain \0"
      VALUE "OriginalFilename", "Sliders\0"
    END
  END
  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x0809, 0x0000
  END
END

CREATEPROCESS_MANIFEST_RESOURCE_ID MANIFEST "Sliders.exe.manifest"

And this is Sliders.exe.manifest (I spied a little bit from FBSL.exe):
Code: [Select]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <assemblyIdentity
      version="1.0.0.0"
      processorArchitecture="X86"
      name="Sliders.Sliders.Sliders"
      type="win32"
  />
  <description>Sliders Puzzle Game</description>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel
          level="asInvoker"
          uiAccess="false"/>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
  </dependency>
</assembly>

I wonder if something is still missing or if I must change something in Sliders.o2bas / Sliders.inc. Or is InitCommonControls forbidden at all if I use a manifest?

Roland


.

Arnold

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #4 on: January 17, 2017, 11:58:34 AM »
Hi John,

Bacon seems to be developed for Linux and there is a Mingw project using GTK. I do not think that this could be helpful for Oxygenbasic. BCX is very interesting and useable with Oxygen. BC9 is object oriented I believe and similiar to BCX(?). What is MBC?

Roland

JRS

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #5 on: January 17, 2017, 12:46:26 PM »
Quote
What is MBC?

MBC = My BASIC Converter/Compiler

It's AIR's Linux/Mac version of BCX that he brings out of the closet from time to time.

Mike Lobanovsky

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #6 on: January 17, 2017, 04:53:00 PM »
@John:

IIRC MBC is Mac-only and console-only port of BCX. (correction: my supposition proved to be wrong by John further down in this thread)

@Roland:

I recompiled your sources with InitCommonControlsEx(). Then I used the resultant 32-bit executable that lacked the manifest only. The manifest I used was:

Code: [Select]
<assembly
   xmlns="urn:schemas-microsoft-com:asm.v1"
   manifestVersion="1.0">
   <assemblyIdentity
      type="win32"
      processorArchitecture="*"
      version="1.0.0.0"
      name="Sliders.exe"
   />
   <description>Slider Puzzle Game</description>
   <dependency>
      <dependentAssembly>
         <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            language="*"
            processorArchitecture="*"
            publicKeyToken="6595b64144ccf1df"
         />
      </dependentAssembly>
   </dependency>
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
        <requestedPrivileges>
        <!-- "asInvoker | requireAdministrator | highestAvailable" uiAccess="false" /> -->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
        </requestedPrivileges>
        </security>
    </trustInfo>
</assembly>

I also used PE Explorer and a hex editor, respectively, to fix the PE checksum and the PE header's .bss section whose virtual size extends beyond its declared size (many GNU tools generate this glitch), and to verify there's no garbage left in the executable file after ResHacker (it does happen from time to time).

For Common Controls v6 that you declare in your manifest, InitCommonControls() is obsolete and fails to load the Comctl32.dll library, so you shouldn't use it anyway. Prefer to use InitCommonControlsEx() instead.

Hotfixed Sliders.exe preserved all its functionality and false alarms dropped from 13 to 4. Below is its screenshot taken under my XP and SysWOW64 Win 7. It also looks and runs as expected under my genuine 32-bit Vista and Win 7. I didn't bother to recompile or fix the 64-bit version though.

.
« Last Edit: January 18, 2017, 02:12:37 AM by Mike Lobanovsky »

JRS

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #7 on: January 17, 2017, 07:11:33 PM »
Mike,

We are very fortunate you're a member of this forum and share your knowledge with us.

Thank You!

Quote
IIRC MBC is Mac-only and console-only port of BCX.

Last version of MBC I downloaded from AIR's site works great on Ubuntu 64 bit.
« Last Edit: January 17, 2017, 08:05:16 PM by John »

Mike Lobanovsky

  • Guest
Re: Dialog as Main Window - Part 2
« Reply #8 on: January 18, 2017, 06:48:58 PM »
John,

It is my pleasure to be part of OxygenBasic community.

And thanks for correcting me. As it turned out, it was I who deleted all traces of Linux from my MBC sources. I now recall I did it to be able to play with AIR's ClaroMac library unhindered. :)