Sunday, March 05, 2023

Microsoft Visual C++ Runtime Library - Debug Assertion Failed!

Microsoft Visual C++ Runtime Library - Debug Assertion Failed!

Running an application in a debug environment throws the following assertion message.

---------------------------
Microsoft Visual C++ Runtime Library
---------------------------
Debug Assertion Failed!

Program: x:\test\myapp.exe
File: minkernel\crts\ucrt\src\appcrt\heap\debug_heap.cpp
Line: 996

Expression: __acrt_first_block == header

For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.

(Press Retry to debug the application)

---------------------------
Abort   Retry   Ignore   
---------------------------

In my specific case, this was caused by a string created in the heap by a DLL and freed in the executable.  The DLL was built using /MDd [Configuration Properties | C/C++ | Code Generation | Runtime Library = Multi-threaded Debug DLL (/MDd)] and the executable was built /MTd with MFC as static library [Configuration Properties | C/C++ | Code Generation | Runtime Library = Multi-thread Debug (/MTd)]/[Configuration Properties | Advanced | Use of MFC = Use MFC in a Static Library]. 

The fix/workaround is to change the executable to use MFC as a shared library [Configuration Properties | Advanced | Use of MFC = Use MFC in a Shared DLL]

//end

Sunday, February 19, 2023

PowerShell Cheat sheet

 

PowerShell Cheat Sheet

While loop

while ($true) {
    Write-Host "Hello World"
}


Append to file

New-TimeSpan -Start @(Get-Process explorer)[0].StartTime | Out-File -Append -FilePath C:\tmp\log.txt


Keywords: PowerShell Quick Tips

REF:003


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

Saturday, January 21, 2023

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

Wednesday, January 04, 2023

Getting 'You are in emergency mode. After logging in, type "journalctl -xb" to view system logs, "systemctl reboot" to reboot, "systemctl default" or "exit" to boot into default mode' after rebooting Linux Mint 21.1 Vera

On my Linux Mint 21.1 Vera machine, rebooting the machine would show the following early in the boot process

You are in emergency mode. After logging in, type "journalctl -xb" to view system logs, "systemctl reboot" to reboot, "systemctl default" or "exit" to boot into default mode.
Press Enter for maintenance
(or press Control-D to continue):

For my specific case this happended because I have a USB drive connected to the CPU. Removing the the USB drive and rebooting the machine allow me to continue with the boot process.

Friday, December 30, 2022

Install TightVNC server on Linux Mint 21.1 Vera

Install TightVNC server on Linux Mint 21.1 Vera

One of the options to manage VirtualBox GUI on a Linux host is via VNC server. Below is quick setup to get it up and running.
$: sudo apt install tightvncserver
It is handy to be able to maintain the same session when connecting to Linux, so let's install tmux, like so:
$: sudo apt install tmux
Once TightVNC server and tmux are installed, run the following to create a session:
$: tmux
$: tightvncserver -nolisten tcp :1 -geometry 1024x768
The above commands creates a new tmux session and runs a new VNC server with geometry of 1024x768 on port :1
In multiple cases, I have observed that the VNC session created was just a solid gray backgroun, no xterm, no nothing. As a work-around install XFCE4 like below
$: sudo apt install xfce4 xfce4-goodies
Then update ~/.vnc/xstartup like below.
#!/bin/sh

xrdb "$HOME/.Xresources"
xsetroot -solid grey
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
# Fix to make GNOME work
export XKL_XMODMAP_DISABLE=1
/etc/X11/Xsession &
startxfce4 &

Installing QNX 6.4.1 on Ubuntu 20.04

Installing QNX 6.4.1 on Ubuntu 20.04 Install pre-requisites $: sudo dpkg --add-architecture i386 $: sudo apt update $: sudo apt install li...