> @CyberShadow right, I could try and allocate more if needed. But how much and how many times? What exception would be thrown if it fails?

I think it's not the task of this module to worry about memory limits.

From the documentation of GetModuleFileName:

> If the buffer is too small to hold the module name, the string is truncated to nSize characters including the terminating null character, the function returns nSize, and the function sets the last error to ERROR_INSUFFICIENT_BUFFER.

So, there you have it. If the first call fails, you'll know exactly how much buffer to allocate.