I did not check it in detail but you evidently forgot to mark the imported functions as using cdecl calling convention. Fix that and it should work.