PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 10
 on: June 03, 2020, 10:51:06 PM 
Started by Paul Squires - Last post by Paul Squires
I won’t list everything that I encounter because obviously the differences between the two languages is immense, however, it is good to dive into topics where the “BASIC way of doing things” is somewhat different than C++.

Terminating statements with semi colon “;”. The problem here is not so much forgetting to do it, but rather remembering when to do it because some things are not terminated with ; whereas other things are. For example, For and Loops and Function bodies are not ; terminated, whereas regular statements, namespaces, classes, are.

Namespaces and the Using statement. From my reading and watching tutorial videos, it became quickly apparent that the general consensus is *not* to use the Using keyword, but rather to prepend statements with the namespace itself. This is because a lot of C++ is in various namespaces and you can quickly run into trouble when trying to switch from namespace to namespace with the Using statement. For example, the std namespace for Standard Library functions is extremely but you should still use the prefix approach nonetheless:
    std::cout << szText << std::endl;

Capitalization. This has already bitten me more than once! Obviously C++ is case sensitive but coming from BASIC I sometimes look at a variable or keyword and wonder why it is not compiling only to realize that I am not spelling it correctly.

Strings and WStrings. Thankfully, C++ has a very strong a robust string class that is fast and handles Unicode easily.
Only issue so far is the concatenation of multiple strings and/or string literals all on one line of code. In BASIC it’s easy, but with C++ the individual strings need to be enclosed in functions in order to make it work. This is only for multiple strings (concatenating two strings works the same in C++ as it does in BASIC):

std::wstring fullstring;
fullstring = std::wstring(L"Hello!") + std::wstring(L" How are you?") + L" End with a literal wide string!"
std::cout << fullstring << std::endl;

WString literals need to be prefixed with an “L”.    L”Paul Squires”

Function parameter default values. You should only define them in the header’s prototype for the function definition, not also in the function itself. In BASIC, we’d put them in both places.

By default, C++ passes all variables by value. This can a performance issue when trying to pass things like large strings or classes into a function. Copies of those incoming elements need to be made. In C, you’d pass a pointer to the object and manipulate that object’s value within the function. In C++, the preferred approach is to pass a reference to the object. You can also pass const with the reference to prevent the function from modifying this income variable. This is especially useful for strings and wstrings. You merely append an ampersand & to the end of the variable type in order to pass it by reference.

Code: [Select]
int myFunction(const std::wstring& wszText)
    std::wcout << wszText << std::endl;

When I call class methods that do not have any parameters, I keep forgetting to end the statement in empty parentheses. For example:

At 1:57 PM on May 30, 2020, I was finally able to get a window to display using g++ and my modified version of Jose Roca’s CWindow class. Using several default parameters, the following code simply displays the window. I’m make progress slowly but I’m learning lots as I go along.

One thing that I have learned…. YOU LEARN BY DOING!!!! Reading and watching tutorials is important but it is no substitute for getting your hands dirty and writing code and learning through trial and error. The concepts get reinforced so much faster that way.

Code: [Select]
// Main entry point
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
    Afx::CWindow win;
    win.Create(0, L"This is my first window", WindowProc);

    return 0;

C++ does not use any “_” line continuation underscores at the end of the line to continue a statement to the next line. Everything is processed and line feeds ignored until the ; is encountered.

For loops, If statements: Do not need to be enclosed in curly braces if they are only one line after the For or If.
for (i = 0; i < 5; i++)

Switch statements only work with integral data types. You can not use a string or wstring class to compare against a string literal. You have to use if/elseif/else statement instead.

Uppercase/Lowercase. This was interesting. There are no built in methods on the string or wstring class to convert the string to upper or lowercase. All my research pointed to either looping the string and converting each character, or using the transform function:
Code: [Select]
#include <algorithm>
std::transform(wsClassName.begin(), wsClassName.end(), wsClassName.begin(), ::toupper);

When the string is transformed to uppercase then you can easily do the comparisons:
if (wsClassName == L"BUTTON") {
    // Adds a button to the window
    if (dwStyle == -1)

Similarly, you can use the compare method of the string class to do the comparison. Returns 0 if the strings are a match:
Code: [Select]
    if ("BUTTON1") == 0) {
        std::cout << "make a button" << std::endl;

Passing strings or wstrings to win32 api functions requires sending it as wszTitle.c_str()

I am leaning a lot on to help with a lot of questions that I have. Every question that I have thought of so far has been answered there over the years.

I am quickly starting to enjoy the brevity that C++ affords. It is less verbose than BASIC especially in relation to setting up the subs/functions and the IF’s, FOR’s, LOOP’s, etc. However, it can be more verbose in areas where you need to work with the standard library or templates. For example, things like I previously mentioned for converting a string to uppercase, or prepending the namespace to the function calls.

Dimensioning variables is so much nicer in C++.
int nHeight = 0;
DIM AS LONG nHeight = 0

Need to remember that the division operator is “/” rather than “\”. Using a backslash “\” usually indicates that you are about to define a literal character.

Don’t forget that == is used to test if things are equal, whereas = is an assignment operator.

Once you start to get used to the keyboard shortcuts in Visual Studio Code you can quickly become VERY productive.

 on: June 03, 2020, 10:40:48 PM 
Started by Paul Squires - Last post by Paul Squires
We will be using a Make system to handle compiling our code. In simple terms, a Make system merely keeps track of the various source files in your application and only recompiles those that have been modified. This significantly speeds up compiling for larger projects as only the changed files need to be recompiled.

We are using CMake, website is located at:

Download the CMake package from get the “Binary distribution” and select the zip file download: Windows win64-x64 ZIP.

Extract that zip so that it is in a folder off of vscode\data\tools

Ensure that you have modified the code.cmd file and updated the CMake folder path in the PATH environment variable. For example:
set PATH=%~dp0data\tools\TDM-GCC-64\bin;%~dp0data\tools\cmake-3.17.2-win64-x64;%PATH%

Go to Settings (Ctrl+,) and select the Extensions branch. Click on the branch called CMake Tools Configuration.

Make these changes:
-   Cmake Path
   If your path is different because you downloaded a different version then update your path accordingly.

-   Mingw Search Dirs
   Click “add Item” and add “.\” (without the double quotes)

A lot of trial and error was involved in trying to find out how to actually compile and run code or how to compile and debug code. VSCode provides a general way through the use of two JSON files, launch.json (debugger instructions) and tasks.json (build instructions). I got these to work for compiling the current active file in the code editor, but once your project starts to grow to multiple files then that system quickly becomes cumbersome, hence the whole reason for CMAKE. That is a make system that controls the compiling and packaging of all necessary files into your final EXE. It only compiles that require re-compiling so subsequent compiles are pretty fast. We never use the launch.json and tasks.json approach.

With everything installed, here is how I start a new project:

Using windows file explorer, I navigate to where I want to store my new project. Every “project” in VSCode is related to an actual physical folder on the drive.
-   Create a new folder. For this example, I name it “MyProject”.
-   Using windows file explorer, I navigate to where I have the portable version of VSCode.
-   Double click the “start_vscode.cmd” file which essentially runs a powershell type of batch file (I listed the contents of that file earlier) that sets some environment variables and then starts up the actual VSCode editor.
-   In VSCode, select File / Open Folder, and navigate to the MyProject folder created in the first step.

At this point there is nothing special going on. Basically you have a blank open project with no files.
-   View / Command Palette (or shortcut, Ctrl+Shift+P) <---- you will use keyboard shortcuts a lot in VSCode.
-   Start typing: cmake into the search bar.
-   Find the entry called: CMake: Quick Start and click on it. This is when the magic starts.
-   CMake will start to configure itself and the first thing it will ask for is “Select a Kit for MyProject”. A ‘kit” is basically a compiler toolchain (remember the TDM-GCC-64 toolchain that we downloaded? We’ll use that one).
-   Select the toolchain. You will probably have many listed especially if you have used Visual Studio at some point in the past. We want to select “GCC for x86_64-w64-mingw32 9.2.0”.
-   If you don’t see the “GCC for x86_64-w64-mingw32 9.2.0” entry in the list, then click on the first option “[Scan for kits]”. This should find your toolchain located off of the app folder.

-   Enter a name for the new project. Just enter “MyProject”.
-   Select “Executable” rather than “Library”.
-   You will now see a lot of CMake configuring taking place. You may also get a popup asking if you wish to add Intellisense support for the folder (click yes of course).

-   You should now see a CMakeList.txt file open in the editor. This is the file that controls our build, run and debugging of our project. A sample main.cpp file will also be created in the folder and you will see it added to the CMakeList file in the add_executable line. Later, if we add more files to our project then we add them in that same line after the main.cpp entry. Basically, that means that it will take the compiled object files of those code files and link them to the main.cpp object to create the final exe.

-   In the Explorer treeview, click on the main.cpp file to show it in the editor. It is just a simple Hello World message that prints to the console.
-   Notice in the bottom statusbar the various options that CMake is giving us related to whether we want to create a debug or release build, toolchain, build, launch the program or debugger. Use those tools to launch our processes. Do not use the options found under the Run menu at the top of the editor.

-   Place your cursor on the first executable line int main(int, char**) In the left had margin click there to place a breakpoint. It should show as a small red circle.
-   Press Ctrl+F5 to build the file and start the debugger. The program should compile and the debug window open and execution stop at line 4. Under the Run menu you will see the debugger keyboard shortcuts: F10, F11, Shift+F11, F5. There should also now be a hovering panel at the top of the editor with several icons that do the same actions.
-   Play around with the debugger and then press F5 to continue executing and end the debugging process.
-   Go back to the Explorer (Ctrl+ShiftE) and expand the newly created folder called Build. In there you will find MyProject.exe


I modified the CMakeLists.txt file to include the follow entries (remove the # character to uncomment any lines that you want to activate). A CMakeLists.txt file basically contains all of the logic that controls how your program is compiled. It is a simple plain ascii text file.

This make file is setup for a simple project that I called win32hello.

Code: [Select]
cmake_minimum_required(VERSION 3.0.0)
project(win32hello VERSION 0.1.0)



target_link_libraries(win32hello -lcomctl32)

# Use -m32 to compile 32-bit exe, and use -m64 to compile 64 bit exe.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -municode")

# Also, if using -m32 then must use the following resource compiler flags
# otherwise the compiling of the resource.rc will fail.
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} --output-format=coff --target=pe-i386")

# -s                   strip out all debug symbols
# -municode            allows call to the unicode wWinMain() entry point
# --subsystem,windows  subsystem turns on/off the console window
# -static-libstdc++
# -static-libgcc
# -std=gnu++17
# -fno-rtti
# -fno-exceptions

# The TDM-GCC-64 toolchain automatically statically links the C++
# standard library and libgcc in order to ensure that running the
# program will work on systems without those libraries.


 on: June 03, 2020, 10:24:22 PM 
Started by Paul Squires - Last post by Paul Squires
It is important to remember that we must always start the Visual Studio Code editor using a script/batch file that we create ourselves. It is modeled after the code.cmd script/batch file found in the root directly. We do not use the code.cmd file itself because that file would get overwritten whenever we do an upgrade of VSCode with new versions. Our new file will set specific environment variables that the editor needs in order to function properly.

Create a new file in the root VSCode folder called start_vscode.cmd. Open that file using any simple text editor like Notepad and copy the following code into it:
Code: [Select]
@echo off

set VSCODE_APPDATA=%~dp0data\appdata
set VSCODE_LOGS=%~dp0data\logs
set VSCODE_EXTENSIONS=%~dp0data\extensions


set PATH=%~dp0data\tools\TDM-GCC-64\bin;%~dp0data\tools\cmake-3.17.3-win64-x64;%PATH%

set VSCODE_FOLDER=%~dp0app
set VSCODE_TOOLS=%~dp0data\tools

call "%~dp0app\Code.exe" "%~dp0app\resources\app\out\cli.js" %*


Go to “Extensions” to install the following extensions:

-   Bookmarks by Alessandro Fragnani
-   C/C++ IntelliSense, debugging… by Microsoft
-   C/C++ Snippets by Harsh
-   CMake Tools by Microsoft
-   Todo Tree by Gruntfuggly
-   Material Theme by Mattia Astorino

VSCode Settings

Access the settings via Ctrl+,
-   Editor: Font Size
   I changed my value to “16” because I have a 4K display.

-   Match Brackets
   I changed mine to “never” because I find it distracting. Maybe later down the road I will find it more useful and will re-enable it.

-   Occurrences Highlight
   I unchecked this option as I find it to be distracting.

-   Selection Highlight
   I unchecked this option as I find it to be distracting.

-   Minimap – Enabled
   I unchecked this option as I find it to be distracting.

-   Color Theme
   Material Theme Darker High Contrast

-   Icon Theme
   Change to “null” because I find that VSCode shows way too many distracting icons everywhere.

-   Tree Indent
   Changed to “14” in order to make the filenames in the Explorer treeview stand out better.

-   Update: Enable Windows Background Updates
   Unchecked. We are using the portable version so we do not want to be bothered having to dismiss the popup dialog box every time a new version becomes available.

Keyboard shortcuts:

Here is where I made a lot of changes. Obviously, these are all personal choices and everyone’s taste for what shortcut should do what, is something that can’t be dictated. I have used my own tools of JellyFish Editor, FireFly, and WinFBE, for so many years that I have become accustomed to what keyboard shortcuts work for me.

Click File, Preferences, Keyboard Shortcuts (Ctrl+K Ctrl+S)

-   (F2) Bookmarks: Jump to Next
-   (Shift+F2) Bookmarks: Jump to Previous
-   (Ctrl+F2) Bookmarks: Toggle
-   (Ctrl+Y) Cut
-   (Ctrl+D) Duplicate Selection
-   (Ctrl+Shift+DownArrow) Move Line Down
-   (Ctrl+Shift+UpArrow) Move Line Up

If you run into (and you will) the situation where a key combination already exists and is tied to another action then you need to delete that binding first. When I was setting up the shortcuts above, none of the bindings that I deleted seemed to relate to anything that I would use regularly in my daily programming.

 on: June 03, 2020, 10:12:10 PM 
Started by Paul Squires - Last post by Paul Squires
In order for Visual Studio Code to compile and/or debug your code, you must install a toolchain. Because we are using a portable version of VSCode, it is easier for use to work with the GCC family of toolchains. These are not native to Windows but the available ports do play nicely with portable setups.


Download a recent TDM-GCC-64 build from:

Select the one called “MinGW-w64 based”. During the installation process install it to the default folder specified, etc. Once installed, copy the entire folder from the installation folder (c:\tdm-gcc-64) to under the “vscode\data\tools” folder (create that tools folder yourself if you have not already done so) for your portable VSCode installation. Once you finish the copy, go into Windows Control Panel and Uninstall TDM-GCC-64 because you no longer need it anymore (we will now use the one that you copied to the vscode\data\tools folder).

Additional step for TDM-GCC-64 (important): I noticed that using this toolkit would fail when trying to initiate a Debugging session.

Here is how to fix it:

Use Windows file explorer to navigate to your \vscode\data\tools\TDM-GCC-64\bin folder. Make a copy of the gdb.exe file. Rename that copy from gdb – Copy.exe to x86_64-w64-mingw32-gdb.exe

CMake Build System

Download the CMake package from get the “Binary distribution” and select the zip file download: Windows win64-x64 ZIP. Extract that zip so that it is in a folder off of vscode\data\tools

I have also evaluated using the mingw-64 8.1 toolchain but I have found that the TDM-GCC-64 works better (and seems to compile faster as well). Actually, TDM-GCC-64 is built using mingw-64 but specific changes an additions were made in order for the toolchain to work better on Windows systems.

I also downloaded and installed the LLVM toolchain (which includes the Clang compiler) into app\LLVM. However, during testing, the Clang compiler will not get recognized because I assume it can not find the MS Build Tools (I haven’t found a way to set that up as portable yet).

I already had Microsoft Build Tools installed (from previously installing Visual Studio Community Edition). It appears that Clang uses the Build Tools (at least on Windows)???? Not 100% sure (I know that it does for Rust but maybe not C++). I have not yet found a way to make the Build Tools portable. You can build/compile using the Build Tools toolchain and will use the Visual C++ compiler. Pretty cool but obviously probably not portable to Linux, etc. For now, until I learn the language better, I will stick with g++ and static linking. Granted the exe’s will be larger but that’s okay.

 on: June 03, 2020, 10:04:16 PM 
Started by Paul Squires - Last post by Paul Squires
I had not settled on an editor/IDE so that search needed to happen and here are the tools that I evaluated with the goal of a fully functional, self contains, portable setup:
-   Dev-C++. Worked okay. A bit dated looking but the deal breaker was that the debugger would crash the system every time I tried to invoke it.

-   CodeBlocks - Meh. Maybe if I ever decide to use wxWidgets for cross platform GUI’s.

-   CodeWrite - Not bad. Pretty basic. Probably works better directly on Linux.

-   Atom – I loved the interface. Clean. However, the support for C++ via extensions was pretty basic.

-   Visual Studio Code (VSCode) – I used this editor for previous web development. It has come a long way since then. I just need to modify the environment to tame down the use of the so many colors and distracting icons. Way too much overkill. Also, the theme itself needed to be changed. I will be using a dark theme even though I have been using light colors in my other editors for years. This ide has it all for C++. Intellisense, linter, formatting, code complete, debugging,… everything I need for just starting out. Also, it is cross platform so I will easily be able to use it on Linux when the time comes.

Download the most recent portable version:

 on: June 03, 2020, 09:51:16 PM 
Started by Paul Squires - Last post by Paul Squires
I broke out the books that I bought in 2014 to learn C++.

Professional C++ (Second Edition), Gregoire, Solter, Kleper

The C++ Standard Library, Nicolai M. Josuttis

Started reading those texts to begin the process of familiarizing myself again with the concepts. Luckily, a lot of what I learned through OOP with FreeBasic made understanding the C++ paradigms much easier. I also started watching many YouTube videos ranging from subject tutorials to conference key note speeches in order to get a feel for the ecosystem.

Helpful YouTube channels:

One of the more helpful YouTube channels was The Cherno. He has a dedicated C++ playlist and is an ex-EA game developer that had worked on the Frostbite engine.

thenewboston (these are a bit simplistic):

And I watch a lot of videos by the language inventor himself, Bjarne Stroustrup, and other superstars in the C++ programming space.

Also, some keynote presentations from CppCon:

Looking at coding standards, I needed to understand how C++ programmers organize their code and how things are named. Basically, what conventions and best practices are used. To that end, I consulted these resources:

C++ Core Guidelines
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices. Herb Sutter, Andrei Alexandrescu
Google C++ Style Guide.

 on: June 03, 2020, 03:37:07 PM 
Started by Paul Squires - Last post by Paul Squires
I have attached the simple win32 test project that I have been using to create my first C++ Windows based program. Of course, it was easy to download and run the C++ windows sample from the Microsoft site, but I wanted to start to integrate Jose's CWindow style of class in order to make the creation of windows a little bit easier.

My initial translation of Jose's CWindow class is included in the download. It is a stripped down version of the original because I only needed the basics.

 on: June 03, 2020, 03:17:52 PM 
Started by Paul Squires - Last post by Paul Squires
Having programmed in BASIC style languages virtually my entire programming life, I recently decided that I would take on the challenge of learning C++.

This sub forum is kind of my self documenting journey as I learn C++.

I still program in FreeBasic and will certainly continue to develop my FB programs, but I also think that it is important for me to finally learn C++ after years of being tempted by it.

If anyone else would like to come along for the journey then by all means you're welcome.

Thirty years is a long time to be programming. Love every minute of it. It is not a job for me but rather a hobby that I use to help me in my job. But it’s more than that – it’s a hobby that enhances my mind and problem solving skills. It’s a learning experience that challenges me to want to learn more. To make things. To make things better, faster, and create something from nothing. It’s a passion that is akin to the times in my life when I learned guitar and woodworking.

Back in the day there were no YouTube videos to help explain programming or language specific concepts. There were online BBS’s and CompuServe, but I was probably too young at the time to really appreciate those resources. Likewise, today we have online training courses and a wealth of printed material available. It’s a great age for learning.

It was dBase III Plus that got me hooked on programming. That was part of my first work term assignment in business school. It was during that time that I wanted to learn more about what languages were available. I looked at Quick C and QuickBasic. C seemed so foreign to me at the time especially given my level of skills that I gravitated to the BASIC style languages more easily. QuickBasic morphed to Visual Basic when Windows programming became dominate over DOS. I quickly became a pretty goo VB programmer but that language certainly shielded you for the most part from the guts of the operating system. Moved to PowerBasic after that and learned so much more about lower level concepts such as pointers and dynamic memory allocation and management. It was at that time that I learned the Windows API – a skill that has proved invaluable for me. In hindsight, that was a great investment of time in order to learn those skills. When PowerBasic died, I moved on to FreeBasic and learned more about classes and other OOP concepts. FB also taught me more about the backend toolchains (GCC in this case).

Throughout my programming life, I have dabbled in other languages obviously. I have gained a base understanding of C syntax in order to help port C code to my BASIC language of choice at the time. I also learned Javascript and several other web technologies in order to build a fully functional web store from scratch for an online business that a friend started. That experience also helped me with Linux and backend server technologies.

Why C++?

Well, it provides total control over building programs and generates extremely efficient code. The syntax can be confusing at times but I am not adverse to a little verbose syntax. The language has an incredibly powerful Standard Library and as many 3rd party tools that I can imagine. The language is also fully Unicode enabled and has an extremely robust String and WString class.

I will also finally get away from the torture of wishing that I had access to some code or library without having to first translate it to a BASIC language. That, in itself, will be quite liberating. Also, C++ will be a huge skill to have for my own personal development. If I don’t take the leap to learn it now then maybe I never will. Will it eventually become my main programming language of choice? Too early to know that. Maybe this whole learning will crash and explode – only time will reveal the truth.

During my transition period when moving from PowerBasic, I had to make decision about what programming language to invest my time in. It was then that I seriously felt that C++ would be that language. It was the GUI part that stagnated that transition. I still needed to make GUI’s and the WinAPI was so natural for me that moving to something else was a big jump. Sure, I guess I could still do WinAPI in C++ but at the time I felt that I may as well learn cross platform. I tried with CodeBlocks and wxWidgets and quickly got discouraged. It was not easy or intuitive. I then moved over to Microsoft’s .Net framework with C#. That was another exercise in frustration. You see, one of my sticky points is that I need my development environment to be portable. It needs to run off a portable hard drive. Obviously, Visual Studio does not fit that requirement. FreeBasic did run easily from a portable drive so I gravitated to that language and have been actively programming in FB for the past five years.

1. C++ Programming Resources

2. Editor - IDE (Visual Studio Code)

3. Toolchain and Make System

4. Visual Studio Code Setup

5. CMake Compiling and Debugging

6. Language Differences between C++ and BASIC’s

 on: June 02, 2020, 10:42:13 AM 
Started by Paul Squires - Last post by Joerg Buckel
Hello Paul

I don't know what's going on now.

It didn't work for me over Whitsun.

Today I'm in the office and the code completion wanted nothing to do with me again....
Now I started the 32bit version of WinFBE and the code completion worked.

Then I started the 64bit variant of WinFBE and ..... the code completion worked this time too.
No matter why. It works at the moment. If the behavior occurs again, I can give you detailed information.

Sometimes I get the feeling that it is only up to me...  ;D
I have worked with the 64bit version.
A new small project with Visual Designer.
So far it was only "standalone" code within the project.
I had not used Tabs, or Tabs to Spaces until now.

But as I mentioned before, this feature does not appear since the start of the 32bit variant.

But as mentioned I can't explain it.


 on: June 02, 2020, 09:34:36 AM 
Started by Paul Squires - Last post by Paul Squires
Thanks Joerg, does it not work in 32 bit and 64 bit? Does it not work in Visual Designer related projects and non- VD projects? Standalone code outside of a project? Do you Tabs, or Tabs to Spaces? I made a lot of changes to the code and hopefully did not break something very important.

Pages: [1] 2 3 ... 10