UnmanagedExports.cs 2.1 KB

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