UnmanagedExports.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // NPP plugin platform for .Net v0.94.00 by Kasper B. Graversen etc.
  2. using System;
  3. using System.Runtime.InteropServices;
  4. using HelloNppPlugin;
  5. using Kbg.NppPluginNET.PluginInfrastructure;
  6. namespace Kbg.NppPluginNET
  7. {
  8. class UnmanagedExports
  9. {
  10. [DllExport(CallingConvention=CallingConvention.Cdecl)]
  11. static bool isUnicode()
  12. {
  13. return true;
  14. }
  15. [DllExport(CallingConvention = CallingConvention.Cdecl)]
  16. static void setInfo(NppData notepadPlusData)
  17. {
  18. PluginBase.nppData = notepadPlusData;
  19. Main.CommandMenuInit();
  20. }
  21. [DllExport(CallingConvention = CallingConvention.Cdecl)]
  22. static IntPtr getFuncsArray(ref int nbF)
  23. {
  24. nbF = PluginBase._funcItems.Items.Count;
  25. return PluginBase._funcItems.NativePointer;
  26. }
  27. [DllExport(CallingConvention = CallingConvention.Cdecl)]
  28. static uint messageProc(uint Message, IntPtr wParam, IntPtr lParam)
  29. {
  30. return 1;
  31. }
  32. static IntPtr _ptrPluginName = IntPtr.Zero;
  33. [DllExport(CallingConvention = CallingConvention.Cdecl)]
  34. static IntPtr getName()
  35. {
  36. if (_ptrPluginName == IntPtr.Zero)
  37. _ptrPluginName = Marshal.StringToHGlobalUni(Main.PluginName);
  38. return _ptrPluginName;
  39. }
  40. [DllExport(CallingConvention = CallingConvention.Cdecl)]
  41. static void beNotified(IntPtr notifyCode)
  42. {
  43. ScNotification notification = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));
  44. if (notification.Header.Code == (uint)NppMsg.NPPN_TBMODIFICATION)
  45. {
  46. PluginBase._funcItems.RefreshItems();
  47. Main.SetToolBarIcon();
  48. }
  49. else if (notification.Header.Code == (uint)NppMsg.NPPN_SHUTDOWN)
  50. {
  51. Main.PluginCleanUp();
  52. Marshal.FreeHGlobal(_ptrPluginName);
  53. }
  54. else
  55. {
  56. Main.OnNotification(notification);
  57. }
  58. }
  59. }
  60. }