How to suppress warnings in external headers in Visual C++

Use this method around (a) header(s) that you cannot or don’t want to change, but which you need to include. You can selectively, and temporarily disable all warnings like this: #pragma warning(push, 0) // Some include(s) with unfixable warnings #pragma warning(pop) Instead of 0 you can optionally pass in the warning number to disable, so … Read more

How to install Visual C++ Build tools?

I just stumbled onto this issue accessing some Python libraries: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”. The latest link to that is actually here: https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019 When you begin the installer, it will have several “options” enabled which will balloon the install size to 5gb. If you have … Read more

Convert char[] to LPCWSTR

For this specific case, the fix is quite simple: wchar_t szBuff[64]; swprintf(szBuff, L”%p”, m_hWnd); MessageBox(NULL, szBuff, L”Test print handler”, MB_OK); That is, use Unicode strings throughout. In general, when programming on Windows, using wchar_t and UTF-16 is probably the simplest. It depends on how much interaction with other systems you have to do, of course. … Read more

msbuild, how to set environment variables?

The coded task can be put right at the project file since MSBuild v4.0. Like this: <UsingTask TaskName=”SetEnvironmentVariableTask” TaskFactory=”CodeTaskFactory” AssemblyFile=”$(MSBuildToolsPath)\Microsoft.Build.Tasks.v$(MSBuildToolsVersion).dll”> <ParameterGroup> <Name ParameterType=”System.String” Required=”true” /> <Value ParameterType=”System.String” Required=”true” /> </ParameterGroup> <Task> <Using Namespace=”System” /> <Code Type=”Fragment” Language=”cs”> <![CDATA[ Environment.SetEnvironmentVariable(Name, Value); ]]> </Code> </Task> </UsingTask> Note that in MSBuild 14+, the AssemblyFile reference should be just: … Read more

Windows C++ stack trace from a running app

The core of the necessary code is StackWalk64. To get much from that, you’ll also want/need to get symbol names with SymGetSymFromAddr64 (which requires SymLoadModule64) and (probably) SymGetLineFromAddr64 and GetThreadContext. If the target was written in C++, you’ll probably also want to use UnDecorateSymbolName. Along with those you’ll need a few ancillaries like SymInitialize, SymCleanup, … Read more