Author Topic: bc9Basic likes TCLib  (Read 8350 times)

0 Members and 1 Guest are viewing this topic.

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
bc9Basic likes TCLib
« on: March 25, 2016, 06:34:45 PM »
bc9Basic likes TCLib.
I tweaked bc9Basic a bit.
WaitKey -> getchar() then ULEX -> _gettchar()
ULEX.EXE does the transformation from ascii cpp code to UNICODE. Best of both worlds.
One source for both.
Added a command line option -tcl that adds and removes items from normal code creation.

I put all the TCLib #includes in my Bc9Adp2 Include folder in their own folder TCLib.
I put the TCLib.Lib in my main Bc9Adp2 Folder.
One of my favorite items from this hacked FreeBasic editor is the ability to set ENVIRONMENT variables before shelling.

James

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: bc9Basic likes TCLib
« Reply #1 on: March 25, 2016, 06:35:49 PM »

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Fred TCLib Demo1
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "FRED.BAT $FILE$"

$HEADER
    #include <windows.h>
    #include "TCLib\stdio.h"
    #include "TCLib\tchar.h"
$HEADER
Function main()
    print "hello, World"
    WaitKey
    Function = EXIT_SUCCESS
End Function


c++ code
Code: [Select]
// *********************************************************************
//  Created with bc9Basic - BASIC To C/C++ Translator (V) 9.2.4.8 (2016/03/21)
//       The bc9Basic translator (bc9.exe) was compiled with
//                           g++ (tdm64-1) 5.1.0
// ----------------------------------------------------------------------
//                 BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
//              Translated for compiling with a C++ Compiler
//                           On MS Windows
// *********************************************************************
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define _X(y) y

// ***************************************************
// Compiler Defines
// ***************************************************
#ifndef __cplusplus
#error A C++ compiler is required
#endif
// $HEADER BEGIN
#include <windows.h>
#include "TCLib\stdio.h"
#include "TCLib\tchar.h"
// $HEADER END


// *************************************************
//        User's GLOBAL ENUM blocks
// *************************************************

// *************************************************
//            System Defined Constants
// *************************************************

typedef const _TCHAR* ccptr;
#define CCPTR const _TCHAR*
#define cfree free
#define EQU ==
#define NOT_USED(x) if(x);
#define CTLHNDL(id) GetDlgItem(hWnd,id)
_TCHAR   *g_cptr_;  // dummy var for not used returns
unsigned int  g_dum1_;  // dummy var for not used returns
#define cSizeOfDefaultString 2048

// *************************************************
//            User Defined Constants
// *************************************************

// *************************************************
//          User Defined Types, Unions and Classes
// *************************************************


// *************************************************
//            User Global Variables
// *************************************************

static _TCHAR*   *g_argv;
static int     g_argc;


// *************************************************
//               User Prototypes
// *************************************************

int     _tmain (int, _TCHAR**);

// *************************************************
//            User Global Initialized Arrays
// *************************************************



// *************************************************
//                 Runtime Functions
// *************************************************


// *************************************************
//       User Subs, Functions and Class Methods
// *************************************************

int _tmain (int argc, _TCHAR** argv)
{
    g_argc = argc;
    g_argv = argv;
    _tprintf(_T("%ls\n"), _T("hello, World"));
    _gettchar();
    return EXIT_SUCCESS;
}

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: bc9Basic likes TCLib
« Reply #2 on: August 09, 2016, 04:41:23 PM »
Fred Harris just released a new version of his TCLIb:
http://www.jose.it-berater.org/smfforum/index.php?topic=5140.msg21947;topicseen#msg21947

This is the first of Fred's TCLib demos with version info added by myself.
You first compose source as if you were writing for a 64 bit ascii app.
The created c++ source is then run through a Unicode lexer, ULEX, which transforms it into c++ UNICODE source before compiliation by the Visual Studio 2015 c++ compiler.

First we have the bc9Basic code:

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Demo1 Dennis Ritchie Classic "Hello, World!"
' I added a Verion function to my TCLib build currently 1.0.0.9
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$NOMAIN
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "TCLIB.BAT $FILE$"
Function main()
    ? Version$()
    ? "Hello World"
    Pause
    Function = 0
End Function



=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
This next is the c++ source before ULEX performs it's magic:
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

// *********************************************************************
//  Created with bc9Basic - BASIC To C/C++ Translator (V) 9.2.5.4 (2016/08/05)
//       The bc9Basic translator (bc9.exe) was compiled with
//                           g++ (tdm64-1) 5.1.0
// ----------------------------------------------------------------------
//                 BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
//              Translated for compiling with a C++ Compiler
//                           On MS Windows
//                    Using TCLib by Fred Harris
// *********************************************************************
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define _X(y) y
#include <windows.h>
#define   x64
#include "TCLib\stdio.h"
#include "TCLib\string.h"
#include "TCLib\stdlib.h"
#include "TCLib\memory.h"
#include "TCLib\malloc.h"
#include "TCLib\math.h"
#include "TCLib\tchar.h"
#include "TCLib\Strings.cpp"
typedef String fstring;
//<---UNICODE AWARE
#define SFMT (const char*)"%s\r\n"
//>---UNICODE AWARE

// NO HEADERS START
#ifndef _WINDOWS_
//<---UNICODE AWARE
typedef _TCHAR *PCHAR, *LPCH, *PCH, *NPSTR, *LPSTR, *PSTR;
typedef unsigned long DWORD, *PDWORD, *LPDWORD;
typedef unsigned int UINT;
//>---UNICODE AWARE
#endif
// NO HEADERS END
// ***************************************************
// Compiler Defines
// ***************************************************
#ifndef __cplusplus
#error A C++ compiler is required
#endif

// *************************************************
//        User's GLOBAL ENUM blocks
// *************************************************

// *************************************************
//            System Defined Constants
// *************************************************

typedef const char* ccptr;
#define CCPTR const char*
#define cfree free
//<---UNICODE AWARE
typedef char _char;
#define _strlen strlen
//>---UNICODE AWARE
#define EQU ==
#define NOT_USED(x) if(x);
#define CTLHNDL(id) GetDlgItem(hWnd,id)
char   *g_cptr_;  // dummy var for not used returns
unsigned int  g_dum1_;  // dummy var for not used returns
int g_dum_int;      // dummy int var for not used returns
#define cSizeOfDefaultString 2048

// *************************************************
//            User Defined Constants
// *************************************************

// *************************************************
//               Standard Prototypes
// *************************************************

void    Pause (void);
// *************************************************
//          User Defined Types, Unions and Classes
// *************************************************

// *************************************************
//            User Global Variables
// *************************************************

static PCHAR   *g_argv;
static int     g_argc;

// *************************************************
//               User Prototypes
// *************************************************

int     main (int, PCHAR*);

// *************************************************
//            User Global Initialized Arrays
// *************************************************


// *************************************************
//                 Runtime Functions
// *************************************************

void Pause(void)
{
    printf("\n%s\n", "Press any key to continue...");
    _getch();
}

// *************************************************
//       User Subs, Functions and Class Methods
// *************************************************

int main (int argc, PCHAR* argv)
{
    g_argc = argc;
    g_argv = argv;
    printf("%s\n", Version());
    printf("%s\n", "Hello World");
    Pause();
    return 0;
}

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
And this the the c++ code after it has been ULEXed
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*

// *********************************************************************
//  Created with bc9Basic - BASIC To C/C++ Translator (V) 9.2.5.4 (2016/08/05)
//       The bc9Basic translator (bc9.exe) was compiled with
//                           g++ (tdm64-1) 5.1.0
// ----------------------------------------------------------------------
//                 BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
//              Translated for compiling with a C++ Compiler
//                           On MS Windows
//                    Using TCLib by Fred Harris
// *********************************************************************
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define _X(y) y
#include <windows.h>
#define   x64
#include "TCLib\stdio.h"
#include "TCLib\string.h"
#include "TCLib\stdlib.h"
#include "TCLib\memory.h"
#include "TCLib\malloc.h"
#include "TCLib\math.h"
#include "TCLib\tchar.h"
#include "TCLib\Strings.cpp"
typedef String fstring;
//<---UNICODE AWARE
#define SFMT (const char*)"%s\r\n"
//>---UNICODE AWARE

// NO HEADERS START
#ifndef _WINDOWS_
//<---UNICODE AWARE
typedef _TCHAR *PCHAR, *LPCH, *PCH, *NPSTR, *LPSTR, *PSTR;
typedef unsigned long DWORD, *PDWORD, *LPDWORD;
typedef unsigned int UINT;
//>---UNICODE AWARE
#endif
// NO HEADERS END
// ***************************************************
// Compiler Defines
// ***************************************************
#ifndef __cplusplus
#error A C++ compiler is required
#endif

// *************************************************
//        User's GLOBAL ENUM blocks
// *************************************************

// *************************************************
//            System Defined Constants
// *************************************************

typedef const _TCHAR* ccptr;
#define CCPTR const _TCHAR*
#define cfree free
//<---UNICODE AWARE
typedef char _char;
#define _strlen strlen
//>---UNICODE AWARE
#define EQU ==
#define NOT_USED(x) if(x);
#define CTLHNDL(id) GetDlgItem(hWnd,id)
_TCHAR   *g_cptr_;  // dummy var for not used returns
unsigned int  g_dum1_;  // dummy var for not used returns
int g_dum_int;      // dummy int var for not used returns
#define cSizeOfDefaultString 2048

// *************************************************
//            User Defined Constants
// *************************************************

// *************************************************
//               Standard Prototypes
// *************************************************

void    Pause (void);
// *************************************************
//          User Defined Types, Unions and Classes
// *************************************************

// *************************************************
//            User Global Variables
// *************************************************

static _TCHAR*   *g_argv;
static int     g_argc;

// *************************************************
//               User Prototypes
// *************************************************

int     _tmain (int, _TCHAR**);

// *************************************************
//            User Global Initialized Arrays
// *************************************************


// *************************************************
//                 Runtime Functions
// *************************************************

void Pause(void)
{
    _tprintf(_T("\n%ls\n"), _T("Press any key to continue..."));
    _getwch();
}


// *************************************************
//       User Subs, Functions and Class Methods
// *************************************************

int _tmain (int argc, _TCHAR** argv)
{
    g_argc = argc;
    g_argv = argv;
    _tprintf(_T("%ls\n"), Version());
    _tprintf(_T("%ls\n"), _T("Hello World"));
    Pause();
    return 0;
}


More to follow.

James




Offline Patrice Terrier

  • ROMs
  • Hero Member
  • *****
  • Posts: 936
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: bc9Basic likes TCLib
« Reply #3 on: December 13, 2016, 09:35:43 AM »
Fred, James, --

Do you have a complete C++ Visual Studio 2015 Community project working with TCLib, i would like to see if it could reduce the size of my own DLL(s) and binaries.

Thank you.
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: bc9Basic likes TCLib
« Reply #4 on: December 13, 2016, 10:45:00 AM »
Patrice,
  Sorry no,I do not use the VS IDE . All compiling is done with a batch file included with the bc9Afx project.

James


Offline Patrice Terrier

  • ROMs
  • Hero Member
  • *****
  • Posts: 936
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: bc9Basic likes TCLib
« Reply #5 on: December 13, 2016, 02:02:33 PM »
Then at least give me the TCLIB and the batch file you are using, to see the parameters being used.
However must be UNICODE ?

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: bc9Basic likes TCLib
« Reply #6 on: December 13, 2016, 04:38:29 PM »
I'd be glad to help Patrice.  I'd like to know if TCLib works with any of your code.  I really suspect it would as from what I know about your coding you are mostly using Win32/64 Api functions.  However, let me say this...

If you are using anything from the C++ Standard Library such as iostream, the C++ std::string / stswstring class, or anything like that - it won't work.  That code needs to be built with the \EHsc flag, that is C++ Exception Handling enabled.  That is one of the main contributors to code bloat in C++ usage.  I know when you first started using C++ you wrote wrappers around a lot of the std::string members to duplicate PowerBASIC String functionality.

What does work is most any use of the basic C Runtime functions in conjunction with just about anything whatsoever from the Win32/64  Api.  That includes just about anything I do and allows for a lot of functionality.  The size of the app doesn't matter.  At this time I'm working on an app with 30 to 40 thousand lines of C++ code and its building fine.  What usage of my TCLib forces is a kind of thought process not many C++ coders use that continually forces one to make a distinction between what functionality is part of the core C++ language as opposed to what functionality is coming from the C++ Standard Library as opposed to the C Standard Library.  The essence and the gist of everything I have done is build an application development environment where everything from the core C++ language including classes and templates is valid, as well as everything from the C Standard Library.     

I have never tried to build a project using TCLib from the Visual Studio IDE but I suspect it could be done.  Maybe I'll give that a shot today.  The really unusual setting involved would be the setting to not link with any of the default libraries Microsoft typically links against, which is LIBC or LIBCMT. 

Another unusual issue is that Microsoft's recent work on refactoring/rewritting the C Standard Library has made things a bit more difficult to use TCLib.  That would apply only to  VStudio 2015.  Not much, but a bit more.  Before 2015 I could use most of the standard includes such as stdio.h, stdlib.h, etc.  The typical syntax of course is #include <stdio.h>.  What that does is use the stdio.h file included with the compiler which is in the compiler's PATH.  However, because of various modifications MS made to various declarators in the function prototypes, there are conflicts with my functions in TCLib.  To solve it it is simply necessary to use my custom includes such as my versions of stdio.h, tchar.h, stdlib.h memory.h, math.h and maybe one or two more.

Anyway, give me a bit and I'll attach my latest version of TCLib and some build scripts I use, and it sounds like James will do the same.  Hopefully you'll be able to get something working.  If you can, I guarantee you'll see some spactular size reductions.   
« Last Edit: December 13, 2016, 04:43:28 PM by Frederick J. Harris »

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: bc9Basic likes TCLib
« Reply #7 on: December 13, 2016, 05:48:36 PM »
Patrice,
My batch file and my version of TCLib is bc9Basic centric.
I added a number of items "I" needed to be compatible with the bc9Basic RTL functions.
That said here is my batch file.
Code: [Select]
@setlocal enableextensions enabledelayedexpansion
@ECHO OFF

SET F=%~nx1
IF EXIST "%F%.cpp" (
  SET FN="%F%.cpp"
  GOTO start
)
GOTO usage

:start

SET XTYPE=x86_amd64
CALL "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%

IF EXIST "%F%.rc" (
  ECHO Compiling resources.....
  Rc "%F%"
  SET VRES="%F%.res"
)

SET WIN_VER=/DWINVER=_WIN32_WINNT_VISTA /D_WIN32_WINNT=_WIN32_WINNT_VISTA
cl %FN%  /O1 /Os /Gy /GS- /GR- /Gs9999999 /Zc:sizedDealloc- %WIN_VER% /link /OPT:REF /STACK:0x100000,0x100000 TCLib.lib kernel32.lib user32.lib %VRES% %2 %3 %4 %5 %6
:cleanup
ECHO Finished!
IF EXIST "%F%.obj" del "%F%.obj"
IF EXIST "Strings.obj" del "Strings.obj"

GOTO done

:usage
ECHO **************************************************************
ECHO  Usage:  TCLIB.BAT MainFile  no ext .cpp assumed
ECHO **************************************************************
:done


James


Offline Patrice Terrier

  • ROMs
  • Hero Member
  • *****
  • Posts: 936
  • User-Rate: +62/-1
    • www.zapsolution.com
Re: bc9Basic likes TCLib
« Reply #8 on: December 13, 2016, 06:01:23 PM »
Fred,

What would help me to start, is a small 64-bit UNICODE "HELLO WORLD" Template, VS 2015 or VS 2013 or VS 2010 project.

Thank you.

...
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: bc9Basic likes TCLib
« Reply #9 on: December 13, 2016, 06:11:33 PM »
Quote
What would help me to start, is a small 64-bit UNICODE "HELLO WORLD" Template, VS 2015 or VS 2013 or VS 2010 project.

I'll try to provide that. 

Attached is the latest TCLib file and associated includes and samples.  I don’t believe there is anything substantial in it that James doesn’t have. 

I just tested it with VC15 (Vstudio 2008, x64) and VC19 (Vstudio 2015, x64). 

The way I use it is as follows.  I open the command prompt window from my Start Menu that either VStudio 2008 or VStudio 2015 put there.  Be careful that you open the one for x64 builds, as there are several of them there.  Actually, I’m not a big Start Menu user, and prefer to put shortcuts to stuff I use all the time on my desktop.  So I transfer them to there. 

When you execute that it will set the paths to the correct build chain.  Then I use the CD command to change the directory to where I have my project. 

So I’d recommend copying all the files in TCLib.zip to some directory where you are working.  Most of the files are the Demo series of samples which I’ve extensively tested.  I’d recommend your starting with those to get your ‘feet wet’, so to speak.

So take Demo1.cpp.  If my command prompt is this…

Code: [Select]
C:\Code\Vstudio\VC++9\Silvah\TCLib>

…I’d paste the command line string after that and hit [ENTER]…

Code: [Select]
C:\Code\Vstudio\VC++9\Silvah\TCLib>cl Demo1.cpp /O1 /Os /GS- TCLib.lib kernel32.lib  [ENTER]

If your paths are right and all the files are there it should build to about 3k x64 with VC19 (Vstudio 2015).

I’d recommend trying all the Demo series of files to familiarize yourself with the working of TCLib.  Many or most of them use my String Class as represented by Strings.h and Strings.cpp.  Try not to confuse those with string.h which is the header for the C Standard Library string primitives, e.g., strcpy, strcat, strlen, etc.

James has a real sophisticated batch file setup for doing all this, but my setup is rather simple and not as sophisticated.  But it might be easier to understand.  When working on a major project I make myself a batch file like so…

Build.bat

Code: [Select]
erase DCSilvah.exe frmCreateNew.obj frmCvta.obj frmExportData.obj frmOutputStatistics.obj frmLandscape.obj frmOutput.obj frmRegen.obj frmViewPlots.obj frmViewRegen.obj Main.obj C:\Silvah\Output.txt C:\Silvah\18001001.sil7
cls
cl @DCSil.txt

All that does is erase previous files I want to get rid of, clear the screen, and execute my build/compilation/linkage string which is contained in another file, which, for the major project I’m working on now, is named DCSil.txt, which looks like this…

Code: [Select]
Main.cpp 
frmLandscape.cpp
frmExportData.cpp
frmOutputStatistics.cpp
frmGotoPlot.cpp
frmCreateNew.cpp
frmCvta.cpp
frmOutput.cpp
frmRegen.cpp
frmViewPlots.cpp
frmViewRegen.cpp

/FeDCSilvah.exe /O1 /Os /GS- /Gs9999999 /GR-
/link /STACK:0x100000,0x100000

TCLib.lib
Kernel32.lib
User32.lib
Gdi32.lib
ComDlg32.lib
ComCtl32.lib
DCSilvahRes.obj
dllSilvah.lib

As you can see above, this is a major project with tens of thousands of lines of code.  To do a build from the command prompt all I need to do is type in ‘Build.bat’ from the command prompt.  Not too hard! 

Patrice, note that in your command line string for your graphics projects you’ll almost surely need the…

Code: [Select]
/Gs9999999 /GR- /link /STACK:0x100000,0x100000

…stack sizing code.  When the Microsoft compiler is running in a /nodefaultlib configuration, which it is for usage with TCLib (internal code within TCLib.lib sets that up), the stack is set to a really small size like only a few thousand bytes or so.  That works fine for my little demo series of programs, where you’ll note those command line settings weren’t used, but for virtually any major production sized program such as yours or mine, we’re going to need a megabyte sized stack allocation for sure.
 




Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: bc9Basic likes TCLib
« Reply #10 on: December 13, 2016, 06:16:24 PM »
Just for the fun of it I'll try to see what it takes to get it working with Visual Studio in the IDE.  But to get started, I'd recommend you try the command line compiling I described above.  It might be a little while before I can post about my IDE attempts, as I've got to run up to work.

Offline James C. Fuller

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 595
  • User-Rate: +11/-8
Re: bc9Basic likes TCLib
« Reply #11 on: December 13, 2016, 06:57:30 PM »
This should work from a normal command prompt:


SET XTYPE=x86_amd64
 "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" %XTYPE%


James

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: bc9Basic likes TCLib
« Reply #12 on: December 14, 2016, 05:26:25 AM »
Couldn't get TCLib working in the IDE with even my VS 2008 Patrice.  I'm 100% sure it can be done; only not by me.  I'm no good at stuff like that.  Sorry. 

But if you aren't too familiar with command line compiling with C++ and Microsoft's cl.exe / link.exe build components, here is a whirlwind tour.

I put a fresh copy of TCLib.lib, stdio.h, stdlib.h, memory.h, tchar.h, string.h, and math.h in this folder...

Code: [Select]
C:\Code\VStudio\VC++9\Silvah\TCLib

In that folder, along with all the rest, is Demo1.cpp…

Code: [Select]
#define  UNICODE
#define  _UNICODE
#include <windows.h>
#include "stdio.h"
#include "tchar.h"

int _tmain()
{
 _tprintf(_T("Hello, World!\n"));
 getchar();

 return 0;
}


To build that with the standard linkages to the C Runtime you would need to change the quotes around stdio.h and tchar.h to the brackets - '<' and '>' like so...

Code: [Select]
#define  UNICODE
#define  _UNICODE
#include <windows.h>
#include <stdio.h>       // <<< Note brackets instead of quotes
#include <tchar.h>       // <<< Note brackets instead of quotes

int _tmain()
{
 _tprintf(_T("Hello, World!\n"));
 getchar();

 return 0;
}

Then on the command line opened to whatever directory contains the file simply type cl Demo1.cpp and hit [ENTER]...

Code: [Select]
C:\Code\VStudio\VC++9\Silvah\TCLib>cl Demo1.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Demo1.cpp
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Demo1.exe
Demo1.obj

C:\Code\VStudio\VC++9\Silvah\TCLib>Demo1
Hello, World!


C:\Code\VStudio\VC++9\Silvah\TCLib>

Above I ran the program and it printed "Hello, World!"

When I checked the folder where the executable was created I found a 56,320 byte Demo1.exe file. 

To build with TCLib the command line is a good bit more complicated.  You first have to make sure we're using "stdio.h" and "tchar.h" though instead of <stdio.h> and <tchar.h>.  Then you would use this command line string...

Code: [Select]
C:\Code\VStudio\VC++9\Silvah\TCLib>cl Demo1.cpp /O1 /Os /GS- TCLib.lib kernel32.lib

The full output is this...

Code: [Select]

C:\Code\VStudio\VC++9\Silvah\TCLib>cl Demo1.cpp /O1 /Os /GS- TCLib.lib kernel32.lib
Microsoft (R) C/C++ Optimizing Compiler Version 15.00.21022.08 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

Demo1.cpp
Microsoft (R) Incremental Linker Version 9.00.21022.08
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:Demo1.exe
Demo1.obj
TCLib.lib
kernel32.lib

C:\Code\VStudio\VC++9\Silvah\TCLib>Demo1
Hello, World!

C:\Code\VStudio\VC++9\Silvah\TCLib>

When I check the file size I'm now at 2,560 bytes but right now I'm on my Win 7 x64 with VS 2008.  On Win 10 with VS 2015 and x64 you'll likely see 3,072 bytes.  But anyway, that's what..... 15 times smaller???  And that's x64 UNICODE.  Can't get much better than that.  Adding my String Class which gives you almost PowerBASIC like String functionality will add all of maybe 1 or 2 k to the file size.  Check out Demo4.cpp.  On that one I'm seeing 4,096 bytes with VS 2015 and my String Class.  With the C++ Standard Library String Class and standard linkages (without TCLib.lib) its about 136,192 bytes.  What more can I say? 

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: bc9Basic likes TCLib
« Reply #13 on: December 14, 2016, 05:30:37 AM »
Oh, and by the way Jim, I did build that resource script program we were working on with my version of TCLib and got the same exact number you posted - it was around 4 k or something like that.  You are right about the resource script GUIs being a bit smaller than comparable RegisterClass()/CreateWindow() apps.  I recall I had to add LPCTSTR, LPCWSTR, and LPCSTR to my tchar.h file, for the WinMain() parameters, which was a needed correction anyway. 

Offline Frederick J. Harris

  • Hero Member
  • *****
  • Posts: 914
  • User-Rate: +16/-0
    • Frederick J. Harris
Re: bc9Basic likes TCLib
« Reply #14 on: December 14, 2016, 05:34:44 AM »
What I'd really love to do if I had time is build that Address PowerBASIC example we were working on a couple years ago with TCLib.  I'm guessing I could get it down to 25 k or so.  I'll have time in a few months when I retire.