[...] but clearly CAST_FROM() cannot handle it.
The same applies to CAST_TO().
[...] problem seem to be only when passing buffer as a as parameter. [...]
Yes. Not only, as you suggesteded, the problem can be avoided declaring the buffer in the local DAT file but also if you declare the buffer as a GLOBAL variable and then using it directly in any subprogram, still without passing it as a parameter.
Thank you very much for the help