Skip to main content

Posts

Showing posts with the label CPP

CPP Quick Guide

Basics Hello world User input While loop If statement For loop Switch statement Read file using ifstream Write to a file using ofstream Containers Basic usage of std::list Basic usage of std::map Basic usage of std::vector Data type conversion Windows API with Exmaples DeviceIoControl FindFirstVolumeW GetDiskFreeSpaceExW GetLogicalDrives GetLogicalDriveStrings C++/WinRT C++/WinRT Hello World Qt Cross-platform Installing Qt Creator 9.0.1 on Windows 10 Qt console hello world Qt Widget hello world Qt Widget hello world code only Keywords: C++, Qt, Programming, Tutorial

C++/WinRT Hello World

C++/WinRT Hello World This is a quick start quide to prepare a development environment to develop against C++/WinRT. System: Development OS: Windows 10 Pro 22H2 Target: Windows 10 LTSB build 10.0.14393 IDE: Visual Studio 2022 (used 17.4.4) Install Visual Studio 2022 Universal Windows Platform development workload. The following is very _important_ as this is what will allow you to create C++/WinRT project. Check C++ (v143) Universal Windows Platform tools , doing so will also enable and install corresponding SDK. Set back and relax as this will download ~24GB of data from Microsoft. After installing Visual Studio, create Windows Console Application (C++/WinRT) For the Minimum version, select Windows 10 Anniversary Update (10.0; Build 14393) The template should look like below If all is well, running it should look like below Keywords: Visual Studio, C++/WinRT

Getting the last error code while debugging even if the Win32 API returned value was not saved

Getting the last error code while debugging even if the Win32 API returned value was not saved It is not uncommon that a Win32 API call return value is not checked in code. This information can prove to be very invaluable while debuging. Fortunately, Visual Studio saves pseudovariables which includes the value normally returned by GetLastError function. To view what would have returned by GetLastError use $err,hr in the Watch window. Refs: Visual Studio Pseudovariables Tags: Visual Studio, CPP

Qt console hello world

Qt console hello world This guide shows how a Qt console hello world looks like. ▣ Open  Qt Creator  and click on  Create Project... ▣ Create Qt Console Application by following the section from @1 to @3.  ▣ In Project Location window provide a project name, i.e., HelloWorldConsole ▣ In Define Build System select CMake ▣ In Translation File , take the default values ▣ In Kit Selection , select the toolchain kit to be used. Below shows only one which is MinGW 64-bit.  ▣ In Project Management, take the default.  ▣ In line 6, I have added an instruction to output Hello World in to the console. Also changed to return 0 to exit the application as event loop is not needed. ▣ Gist source code shown below for convenience ▣ Running it using Qt Creator is well and good but we probably want to run it external to the IDE. To deploy the binary with all the dependencies, open the compiler environment used to build the application. In the case above we have used Qt 6.4.1 (MinGW 11.2.0 64-bit)

Installing Qt Creator 9.0.1 on Windows 10

Installing Qt Creator 9.0.1 on Windows 10 This is a quick guide on installing Qt Creator 9.0.1 on Windows 10. As of December 24, 2022, the latest available online installer is qt-unified-windows-x64-4.5.1-online.exe . Binaries can be downloaded from https://www.qt.io/download , I was using Qt for open source use. What follows are the screen captures to get working installation of Qt Creator (Qt 6.4.1). Welcome Screen Accept open source obligations Welcome to open source Qt setup Contribute to Qt development Installation Folder - Custom installation Select Components - Use default, add "MinGW 11.2.0 64-bit" License Agreement Start Menu Shortcuts Ready to Install Installing Finished Keywords: Qt Creator, CPP

Installing Qt Creator 4.11.x on Windows 10

This is a quick guide on installing Qt Creator 4.11.x on Windows 10. * Download the QT Online Installer (as of March 2020 it can be downloaded from here ). * Run qt-unified-windows-x86-3.2.2-online.exe and follow the installation wizard like below Welcome screen Create an account or login  Accept Qt Open Source obligations Setup Qt Contribute to Qt Create User Experience Development Select installation folder Select Components - Default selection Select MinGW 7.3.0 32-bit and MinGW 7.3.0 64-bit Under Developer and Designer Tools - check MinGW 7.3.0 32-bit/64-bit Accept License Agreement Start Menu Shortcuts Ready to Install Installing Qt Creating Maintenance Tool Completing the Qt Wizard Qt Creator! Keywords: Qt Creator, MinGW 7.3.x

CPP: Windows: GetDiskFreeSpaceExW

CPP: Windows: GetDiskFreeSpaceExW Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread. Notes: - Tested using Visual Studio 2022 (17.2.6) C++ Windows Console template Reference(s): https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getdiskfreespaceexw

CPP: Windows: FindFirstVolumeW

CPP: Windows: FindFirstVolumeW Retrieves the name of a volume on a computer. FindFirstVolume is used to begin scanning the volumes of a computer. See line 85 for sample usage Notes: - Tested using Visual Studio 2022 (17.2.6) C++ Windows Console template Reference(s): https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstvolumew

CPP: Windows: DeviceIoControl

CPP: Windows: DeviceIoControl An application can use the DeviceIoControl function to perform direct input and output operations on, or retrieve information about, a floppy disk drive, hard disk drive, tape drive, or CD-ROM drive. The following example demonstrates how to retrieve information about the first physical drive in the system. It uses the CreateFile function to retrieve the device handle to the first physical drive, and then uses DeviceIoControl with the IOCTL_DISK_GET_DRIVE_GEOMETRY control code to fill a DISK_GEOMETRY structure with information about the drive. Notes: - Tested using Visual Studio 2022 (17.2.6) C++ Windows Console template Reference(s): https://docs.microsoft.com/en-us/windows/win32/devio/calling-deviceiocontrol