Okay, first, I was wrong about the datatype, your Declare statement should have the PackedTemplatePtr and PackedMaskPtr as Integer, not Long (this goes for the Template and Mask variables as well). Try that and see what happens.

Am I right in assuming the called function will return the pointer into those passed variables?