UPDATE: this was my mistake. I used rundll32.exe to execute my DLL. Apparently, as rundll32 was originally designed to run Windows modules it is not suitable for custom-made DLL libraries.
My DLL runs normally if called not by rundll32.