UnmanagedExports.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace Demo
  4. {
  5. internal class UnmanagedExports
  6. {
  7. [DllExport(ExportName = "isUnicode", CallingConvention = CallingConvention.Cdecl)]
  8. private static bool IsUnicode()
  9. {
  10. return true;
  11. }
  12. [DllExport(ExportName = "setInfo", CallingConvention = CallingConvention.Cdecl)]
  13. private static void SetInfo(NppData notepadPlusData)
  14. {
  15. PluginBase.NppData = notepadPlusData;
  16. PluginBase.CommandMenuInit();
  17. }
  18. [DllExport(ExportName = "getFuncsArray", CallingConvention = CallingConvention.Cdecl)]
  19. private static IntPtr GetFuncsArray(ref int nbF)
  20. {
  21. nbF = PluginBase.FuncItems.Items.Count;
  22. return PluginBase.FuncItems.NativePointer;
  23. }
  24. [DllExport(ExportName = "messageProc", CallingConvention = CallingConvention.Cdecl)]
  25. private static uint MessageProc(uint message, IntPtr wParam, IntPtr lParam)
  26. {
  27. return 1;
  28. }
  29. private static IntPtr _ptrPluginName = IntPtr.Zero;
  30. [DllExport(ExportName = "getName", CallingConvention = CallingConvention.Cdecl)]
  31. private static IntPtr GetName()
  32. {
  33. if (_ptrPluginName == IntPtr.Zero)
  34. _ptrPluginName = Marshal.StringToHGlobalUni(PluginBase.PluginName);
  35. return _ptrPluginName;
  36. }
  37. [DllExport(ExportName = "beNotified", CallingConvention = CallingConvention.Cdecl)]
  38. private static void BeNotified(IntPtr notifyCode)
  39. {
  40. var nc = (ScNotification)Marshal.PtrToStructure(notifyCode, typeof(ScNotification));
  41. if (nc.nmhdr.code == (uint)NppMsg.NPPN_TBMODIFICATION)
  42. {
  43. PluginBase.FuncItems.RefreshItems();
  44. PluginBase.SetToolBarIcon();
  45. }
  46. else if (nc.nmhdr.code == (uint)SciMsg.SCN_CHARADDED)
  47. {
  48. PluginBase.DoInsertHtmlCloseTag((char)nc.ch);
  49. }
  50. else if (nc.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN)
  51. {
  52. PluginBase.PluginCleanUp();
  53. Marshal.FreeHGlobal(_ptrPluginName);
  54. }
  55. }
  56. }
  57. }