From 91312adceaed02f7023b30a5af812ed33d8ba4e8 Mon Sep 17 00:00:00 2001 From: David Sungaila Date: Fri, 20 Sep 2024 14:43:23 +0200 Subject: [PATCH] Fix P/Invoke --- .github/workflows/dotnet.yml | 14 ++------------ src/PDFtoImage/Internals/NativeMethods.cs | 23 ++++------------------- 2 files changed, 6 insertions(+), 31 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index a5b233ea..06863cdf 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -128,21 +128,11 @@ jobs: strategy: fail-fast: false matrix: - os: [windows-2019, windows-2022, ubuntu-20.04, ubuntu-22.04, ubuntu-24.04, macos-12, macos-13, macos-14] + os: [windows-2019, windows-2022, ubuntu-20.04, ubuntu-22.04, macos-12, macos-13, macos-14] runs-on: ${{ matrix.os }} if: success() && (github.event_name != 'workflow_dispatch' && true || inputs.run_tests) == true steps: - - name: Setup Mono (macOS) - if: runner.os == 'macOS' - run: | - sudo chown -R $(whoami) $(brew --prefix)/* - brew install mono - - name: Setup Mono (Ubuntu) - if: runner.os == 'Linux' - run: | - sudo apt-get update - sudo apt-get install -y mono-devel - - name: Setup Mono (Windows) + - name: Setup Mono if: runner.os == 'Windows' run: choco install mono -y && Add-Content $env:GITHUB_PATH "C:\Program Files\Mono\bin" - name: Setup .NET diff --git a/src/PDFtoImage/Internals/NativeMethods.cs b/src/PDFtoImage/Internals/NativeMethods.cs index 08c2def5..7bfb5b71 100644 --- a/src/PDFtoImage/Internals/NativeMethods.cs +++ b/src/PDFtoImage/Internals/NativeMethods.cs @@ -166,11 +166,11 @@ public static IntPtr FPDFBitmap_CreateEx(int width, int height, FPDFBitmap forma } } - public static void FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color) + public static bool FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color) { lock (LockString) { - Imports.FPDFBitmap_FillRect(bitmapHandle, left, top, width, height, color); + return Imports.FPDFBitmap_FillRect(bitmapHandle, left, top, width, height, color) != 0; } } @@ -182,14 +182,6 @@ public static void FPDFBitmap_Destroy(IntPtr bitmapHandle) } } - public static uint FPDFDest_GetDestPageIndex(IntPtr document, IntPtr dest) - { - lock (LockString) - { - return Imports.FPDFDest_GetDestPageIndex(document, dest); - } - } - /// /// Opens a document using a .NET Stream. Allows opening huge /// PDFs without loading them into memory first. @@ -354,16 +346,12 @@ private static partial class Imports [LibraryImport("pdfium")] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] - public static partial void FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color); + public static partial int FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color); [LibraryImport("pdfium")] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial void FPDFBitmap_Destroy(IntPtr bitmapHandle); - [LibraryImport("pdfium")] - [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] - public static partial uint FPDFDest_GetDestPageIndex(IntPtr document, IntPtr dest); - [LibraryImport("pdfium")] [UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])] public static partial uint FPDF_GetLastError(); @@ -442,14 +430,11 @@ private static partial class Imports public static extern IntPtr FPDFBitmap_CreateEx(int width, int height, int format, IntPtr first_scan, int stride); [DllImport("pdfium", CallingConvention = CallingConvention.Cdecl)] - public static extern void FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color); + public static extern int FPDFBitmap_FillRect(IntPtr bitmapHandle, int left, int top, int width, int height, uint color); [DllImport("pdfium", CallingConvention = CallingConvention.Cdecl)] public static extern void FPDFBitmap_Destroy(IntPtr bitmapHandle); - [DllImport("pdfium", CallingConvention = CallingConvention.Cdecl)] - public static extern uint FPDFDest_GetDestPageIndex(IntPtr document, IntPtr dest); - [DllImport("pdfium", CallingConvention = CallingConvention.Cdecl)] public static extern uint FPDF_GetLastError();