There are two things you can try:
(1) Pass a Ctring& into the DLL instead of returning a CString.
The problem will NOT disappear, but debugging is easier!
(2) Instead of returning a CString, return a BSTR which can be created easily from CString inside your DLL:
BSTR dll_bstr = str.AllocSysString();
Convert the BSTR back into a CString in your exe (e.g. use _bstr_t)
and the BSTR must of course be deleted in your exe! But this is done by "standard" API functions and does not depend on Compiler settings:
::SysFreeString(exe_bstr);