Add calling convention attributes to unmanaged function pointers.

This commit is contained in:
H. Utku Maden 2024-11-18 19:32:40 +03:00
parent 8e8c86b2c1
commit 50c37e58fc
2 changed files with 8 additions and 2 deletions

@ -12,18 +12,23 @@ namespace ReFuel.Stb
/// <param name="buffer">C array to read into.</param> /// <param name="buffer">C array to read into.</param>
/// <param name="count">Size of the C array in bytes.</param> /// <param name="count">Size of the C array in bytes.</param>
/// <returns>The number of bytes read from the stream.</returns> /// <returns>The number of bytes read from the stream.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate int StbiReadProc(void *userdata, byte* buffer, int count); public unsafe delegate int StbiReadProc(void *userdata, byte* buffer, int count);
/// <summary> /// <summary>
/// Pointer to STBI stream skip function. /// Pointer to STBI stream skip function.
/// </summary> /// </summary>
/// <param name="userdata">User provided userdata pointer.</param> /// <param name="userdata">User provided userdata pointer.</param>
/// <param name="count">Number of bytes to skip.</param> /// <param name="count">Number of bytes to skip.</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void StbiSkipProc(void *userdata, int count); public unsafe delegate void StbiSkipProc(void *userdata, int count);
/// <summary> /// <summary>
/// Pointer to STBI stream end of file function. /// Pointer to STBI stream end of file function.
/// </summary> /// </summary>
/// <param name="userdata">User provided userdata pointer.</param> /// <param name="userdata">User provided userdata pointer.</param>
/// <returns>Non-zero value if the end of the stream has been reached.</returns> /// <returns>Non-zero value if the end of the stream has been reached.</returns>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate int StbiEofProc(void *userdata); public unsafe delegate int StbiEofProc(void *userdata);
/// <summary> /// <summary>
@ -123,4 +128,4 @@ namespace ReFuel.Stb
public static implicit operator IntPtr(in StbiWriteStreamWrapper wrapper) => wrapper.Callback; public static implicit operator IntPtr(in StbiWriteStreamWrapper wrapper) => wrapper.Callback;
} }
} }

@ -9,6 +9,7 @@ namespace ReFuel.Stb.Native
/// <param name="context">User provided context pointer.</param> /// <param name="context">User provided context pointer.</param>
/// <param name="data">C Array of data to write.</param> /// <param name="data">C Array of data to write.</param>
/// <param name="size">Size of the C array in bytes.</param> /// <param name="size">Size of the C array in bytes.</param>
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void StbiWriteProc(void* context, void* data, int size); public unsafe delegate void StbiWriteProc(void* context, void* data, int size);
public unsafe partial class Stbi public unsafe partial class Stbi
@ -24,7 +25,7 @@ namespace ReFuel.Stb.Native
} }
public static int write_png_compression_level public static int write_png_compression_level
{ {
get => *_png_compression_level_ptr; get => *_png_compression_level_ptr;
set => *_png_compression_level_ptr = value; set => *_png_compression_level_ptr = value;
} }