Fixed HANDLE prototypes in FFI code and added some custom typedefs.