result = cast[ptr ITestIntf](intf) probably what you want is result = cast[ptr ITestIntf](intf.addr).
use addr operator to get the address of a variable. returning something on the stack is very dangerous, the time you exit/returned from the proc, the object on the stack may be already replaced by something else or already gone. maybe you should put in on global space