NativeMethods.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace PaintDotNet.SystemLayer.GpcWrapper
  4. {
  5. internal static class NativeMethods
  6. {
  7. private static class X64
  8. {
  9. [DllImport("ShellExtension_x64.dll")]
  10. public static extern void gpc_polygon_clip(
  11. [In] NativeConstants.gpc_op set_operation,
  12. [In] ref NativeStructs.gpc_polygon subject_polygon,
  13. [In] ref NativeStructs.gpc_polygon clip_polygon,
  14. [In, Out] ref NativeStructs.gpc_polygon result_polygon);
  15. [DllImport("ShellExtension_x64.dll")]
  16. public static extern void gpc_free_polygon([In] ref NativeStructs.gpc_polygon polygon);
  17. }
  18. private static class X86
  19. {
  20. [DllImport("ShellExtension_x86.dll")]
  21. public static extern void gpc_polygon_clip(
  22. [In] NativeConstants.gpc_op set_operation,
  23. [In] ref NativeStructs.gpc_polygon subject_polygon,
  24. [In] ref NativeStructs.gpc_polygon clip_polygon,
  25. [In, Out] ref NativeStructs.gpc_polygon result_polygon);
  26. [DllImport("ShellExtension_x86.dll")]
  27. public static extern void gpc_free_polygon([In] ref NativeStructs.gpc_polygon polygon);
  28. }
  29. public static void gpc_polygon_clip(
  30. [In] NativeConstants.gpc_op set_operation,
  31. [In] ref NativeStructs.gpc_polygon subject_polygon,
  32. [In] ref NativeStructs.gpc_polygon clip_polygon,
  33. [In, Out] ref NativeStructs.gpc_polygon result_polygon)
  34. {
  35. if (Processor.Architecture == ProcessorArchitecture.X64)
  36. {
  37. X64.gpc_polygon_clip(set_operation, ref subject_polygon, ref clip_polygon, ref result_polygon);
  38. }
  39. else if (Processor.Architecture == ProcessorArchitecture.X86)
  40. {
  41. X86.gpc_polygon_clip(set_operation, ref subject_polygon, ref clip_polygon, ref result_polygon);
  42. }
  43. else
  44. {
  45. throw new InvalidOperationException();
  46. }
  47. }
  48. public static void gpc_free_polygon([In] ref NativeStructs.gpc_polygon polygon)
  49. {
  50. if (Processor.Architecture == ProcessorArchitecture.X64)
  51. {
  52. X64.gpc_free_polygon(ref polygon);
  53. }
  54. else if (Processor.Architecture == ProcessorArchitecture.X86)
  55. {
  56. X86.gpc_free_polygon(ref polygon);
  57. }
  58. else
  59. {
  60. throw new InvalidOperationException();
  61. }
  62. }
  63. }
  64. }