FFI fixes

Fix issue #301 and errors detected by #294.

In most cases the generated code use a wrong types (Custom types in extern classes aren't visible inside the main generated code). Also fixed an alias.