The issue comes from the static initialization order.
Because the file name is declared as static which depends of other statics (I have a lot of static variable int this project), I have got uninitialized variable as parameter. This is the reason why it raised the exception with bad argument.
I could track this phenomenon thanks to breakpoints at the variable initialization and the execution of the function. The execution happened first...
However, it could be a good idea to make a trace of the parameter (rather an OutputDebugString
or something to force display since trace won't work in release mode) before entering in the function.