I managed to have a similiar problem though in C++. Code
worked fine when it was compiled as a shared MFC and
didn't worked at all when compiled as static MFC (MFC
was compiled inside my DLL), anyway, the solution was
the same, moving the code to an upper scope.