If you ship your library/application to Windows, please use UTF-16 interfaces

TL;DR: Do as the title says, or your library/application won’t function properly in certain situations.

Here’s a small program that takes a file path as a parameter, and queries its size:

#include <iostream>
#include <sys/stat.h>
int main (int /*argc*/, char* argv[])
struct stat fileInfo;
if (stat (argv[1], &fileInfo) == 0) {
std::cout << "The file's size is: " << fileInfo.st_size <<
" bytes" << std::endl;
} else {
std::cout << "Unable to stat file (maybe it doesn't exist?)" <<
view raw FileSize.cpp hosted with ❤ by GitHub

Even though stat is a POSIX function, it happens to be available on Windows as well, so this nice program works on both POSIX platforms and Windows. Or does it?

Continue reading “If you ship your library/application to Windows, please use UTF-16 interfaces”

Detecting if the Visual Studio C++ Redistributable is installed

TL;DR: It’s worth not just detecting, but also trying out whether it actually works.

If you ship software on Windows written in C++ and compiled with the MSVC toolchain, then you probably heard about the so-called “Visual Studio C++ Redistributable”. Chances are that you link your binaries against the dynamic runtime DLLs, which means that your application has a runtime dependency of (at least some of the) DLLs contained in this redistributable package.

When your product is installed, you (or the installer framework you use) have to make sure that the appropriate version of the redistributable is also installed, or your program will fail to start. In this post, I’ll reason about why you shouldn’t settle for merely detecting whether this dependency is installed, with two real-world examples.

Continue reading “Detecting if the Visual Studio C++ Redistributable is installed”