From 51e907c959ffece7c6c700e6b133fc5d382b9f6a Mon Sep 17 00:00:00 2001 From: Jameson Ernst Date: Sun, 14 Jul 2013 21:24:26 -0700 Subject: [PATCH] Marshaling refinements to supplementary libraries --- src/SDL2_image.cs | 7 +++++-- src/SDL2_mixer.cs | 13 ++++++++++--- src/SDL2_ttf.cs | 47 ++++++++++++++++++++++++++--------------------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/SDL2_image.cs b/src/SDL2_image.cs index 6337211..e2a0641 100644 --- a/src/SDL2_image.cs +++ b/src/SDL2_image.cs @@ -61,7 +61,7 @@ namespace SDL2 IMG_INIT_WEBP = 0x00000008 } - public static void SDL_IMAGE_VERSION(ref SDL.SDL_version X) + public static void SDL_IMAGE_VERSION(out SDL.SDL_version X) { X.major = SDL_IMAGE_MAJOR_VERSION; X.minor = SDL_IMAGE_MINOR_VERSION; @@ -107,7 +107,10 @@ namespace SDL2 /* IntPtr refers to an SDL_Surface* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr IMG_ReadXPMFromArray(ref char[] xpm); + public static extern IntPtr IMG_ReadXPMFromArray( + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)] + string[] xpm + ); #endregion } diff --git a/src/SDL2_mixer.cs b/src/SDL2_mixer.cs index 8d669df..00e0776 100644 --- a/src/SDL2_mixer.cs +++ b/src/SDL2_mixer.cs @@ -137,7 +137,7 @@ namespace SDL2 IntPtr b // void* ); - public static void SDL_MIXER_VERSION(ref SDL.SDL_version X) + public static void SDL_MIXER_VERSION(out SDL.SDL_version X) { X.major = SDL_MIXER_MAJOR_VERSION; X.minor = SDL_MIXER_MINOR_VERSION; @@ -205,11 +205,18 @@ namespace SDL2 /* IntPtr refers to a Mix_Chunk* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern IntPtr Mix_QuickLoad_WAV(byte[] mem); + public static extern IntPtr Mix_QuickLoad_WAV( + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1)] + byte[] mem + ); /* IntPtr refers to a Mix_Chunk* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] - public static extern Mix_Chunk Mix_QuickLoad_RAW(byte[] mem, uint len); + public static extern Mix_Chunk Mix_QuickLoad_RAW( + [In()] [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.U1, SizeParamIndex = 1)] + byte[] mem, + uint len + ); /* chunk refers to a Mix_Chunk* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] diff --git a/src/SDL2_ttf.cs b/src/SDL2_ttf.cs index 4edea5c..430c5db 100644 --- a/src/SDL2_ttf.cs +++ b/src/SDL2_ttf.cs @@ -66,7 +66,7 @@ namespace SDL2 public const int TTF_HINTING_MONO = 2; public const int TTF_HINTING_NONE = 3; - public static void SDL_TTF_VERSION(ref SDL.SDL_version X) + public static void SDL_TTF_VERSION(out SDL.SDL_version X) { X.major = SDL_TTF_MAJOR_VERSION; X.minor = SDL_TTF_MINOR_VERSION; @@ -188,11 +188,11 @@ namespace SDL2 public static extern int TTF_GlyphMetrics( IntPtr font, ushort ch, - ref int minx, - ref int maxx, - ref int miny, - ref int maxy, - ref int advance + out int minx, + out int maxx, + out int miny, + out int maxy, + out int advance ); /* font refers to a TTF_Font* */ @@ -201,8 +201,8 @@ namespace SDL2 IntPtr font, [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] string text, - ref int w, - ref int h + out int w, + out int h ); /* font refers to a TTF_Font* */ @@ -211,24 +211,25 @@ namespace SDL2 IntPtr font, [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] string text, - ref int w, - ref int h + out int w, + out int h ); /* font refers to a TTF_Font* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern int TTF_SizeUNICODE( IntPtr font, - ushort[] text, - ref int w, - ref int h + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, + out int w, + out int h ); /* IntPtr refers to an SDL_Surface*, font to a TTF_Font* */ [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Solid( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg ); @@ -246,7 +247,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Solid( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg ); @@ -262,7 +264,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Shaded( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg, SDL.SDL_Color bg @@ -282,7 +284,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Shaded( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg, SDL.SDL_Color bg ); @@ -300,7 +303,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Blended( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg ); @@ -318,7 +321,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Blended( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg ); @@ -326,7 +330,7 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderText_Blended_Wrapped( IntPtr font, - [In()] [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(LPUtf8StrMarshaler))] + [In()] [MarshalAs(UnmanagedType.LPStr)] string text, SDL.SDL_Color fg, uint wrapped @@ -346,7 +350,8 @@ namespace SDL2 [DllImport(nativeLibName, CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr TTF_RenderUNICODE_Blended_Wrapped( IntPtr font, - ushort[] text, + [In()] [MarshalAs(UnmanagedType.LPWStr)] + string text, SDL.SDL_Color fg, uint wrapped );