>> while both the exe and dll that is written in C++ are compiled with the _cdecl flag.
But when you use the function you are using it with the CALLBACK specifier, which is stdcall not cdecl. This is resulting in a stack-frame mis-match between the caller and the callee, hence the error about the stack pointer.