Community
    • Login

    NppPluginNET 64-bit?

    Scheduled Pinned Locked Moved Notepad++ & Plugin Development
    csharppluginnet
    13 Posts 6 Posters 16.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dailD
      dail
      last edited by

      Does anyone know of a shared/maintained repo for this project?

      @Kasper-Graversen has done some great work updating it. https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net

      As to your other questions, I can’t say since I don’t use C#.

      1 Reply Last reply Reply Quote 0
      • AdrianHHHA
        AdrianHHH
        last edited by

        One of your questions is “Does anyone know whether there’s a good way to get debugging information out of the plugin loading process, to get an idea of what any errors might be?”. I wrote a try…catch around part of the plugin start up code and write the results into a buffer. Not the best approach but a workaround for use during plugin development. See more details on Stack Overflow.

        1 Reply Last reply Reply Quote 0
        • chcgC
          chcg
          last edited by

          Caused by problematic pointer arithmetic in

              public void Add(FuncItem funcItem)
          

          and
          public void RefreshItems()

          in class FuncItems in NppPluginNETHelper.cs, like:

                  IntPtr ptrPosNewItem = (IntPtr)((int)newPointer + oldSize);
          

          So the cast to int from type IntPtr shortens the pointer for X64, see e.g.

          https://blogs.msdn.microsoft.com/jaredpar/2008/11/11/properly-incrementing-an-intptr/
          or
          https://stackoverflow.com/questions/1866236/add-offset-to-intptr

          chcgC 1 Reply Last reply Reply Quote 0
          • chcgC
            chcg @chcg
            last edited by

            Created https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/pull/19 therefore.

            Kasper GraversenK 1 Reply Last reply Reply Quote 1
            • Kasper GraversenK
              Kasper Graversen @chcg
              last edited by

              @chcg Great.

              1 Reply Last reply Reply Quote 0
              • chcgC
                chcg
                last edited by

                As mentioned above probably also an update of the included dllexport is necessary for real x64 usability. At

                https://www.nuget.org/packages/UnmanagedExports

                the latest version there is 1.2.7. The followup nuget package with a somehow different structure is available in version 1.5 at:

                https://www.nuget.org/packages/DllExport/

                1 Reply Last reply Reply Quote 0
                • greenzestG
                  greenzest
                  last edited by

                  I don’t know if this will be helpful to anyone but…

                  You will also need to make the following modification for your C# plugin to work on x64 :

                  • Change from int to IntPtr in the notification structure (compare what you have to what’s below)
                      [StructLayout(LayoutKind.Sequential)]
                      public struct Sci_NotifyHeader {
                          /* Compatible with Windows NMHDR.
                           * hwndFrom is really an environment specific window handle or pointer
                           * but most clients of Scintilla.h do not have this type visible. */
                          public IntPtr hwndFrom;
                          public IntPtr idFrom;
                          public uint code;
                      }
                  
                      [StructLayout(LayoutKind.Sequential)]
                      public struct SCNotification {
                          public Sci_NotifyHeader nmhdr;
                          public int position; /* SCN_STYLENEEDED, SCN_MODIFIED, SCN_DWELLSTART, SCN_DWELLEND */
                          public int ch; /* SCN_CHARADDED, SCN_KEY */
                          public int modifiers; /* SCN_KEY */
                          public int modificationType; /* SCN_MODIFIED */
                          public IntPtr text; /* SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION */
                          public int length; /* SCN_MODIFIED */
                          public int linesAdded; /* SCN_MODIFIED */
                          public int message; /* SCN_MACRORECORD */
                          public IntPtr wParam; /* SCN_MACRORECORD */
                          public IntPtr lParam; /* SCN_MACRORECORD */
                          public int line; /* SCN_MODIFIED */
                          public int foldLevelNow; /* SCN_MODIFIED */
                          public int foldLevelPrev; /* SCN_MODIFIED */
                          public int margin; /* SCN_MARGINCLICK */
                          public int listType; /* SCN_USERLISTSELECTION */
                          public int x; /* SCN_DWELLSTART, SCN_DWELLEND */
                          public int y; /* SCN_DWELLSTART, SCN_DWELLEND */
                          public int token; /* SCN_MODIFIED with SC_MOD_CONTAINER */
                          public int annotationLinesAdded; /* SC_MOD_CHANGEANNOTATION */
                          public int updated; /* SCN_UPDATEUI */
                          public int listCompletionMethod; /* SCN_AUTOCSELECTION, SCN_AUTOCCOMPLETED, SCN_USERLISTSELECTION */
                      }
                  
                  • modify your sendmessage P/Invoke to NO LONGER use int or bool (see this page); instead use the following signature :
                  [DllImport("user32.dll", CharSet = CharSet.Auto)]
                  static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
                  

                  For information, i post the modifications on my end to make it work :
                  https://github.com/jcaillon/3P/commit/63d0f408489605cbaefe50d4565515ef70959e2e#diff-009e4601aad253f284d4f65fdba02937
                  https://github.com/jcaillon/3P/commit/63d0f408489605cbaefe50d4565515ef70959e2e#diff-e465f2e4346ecedd11f61657df6d2415
                  https://github.com/jcaillon/3P/commit/63d0f408489605cbaefe50d4565515ef70959e2e#diff-a583b7dff72eb31fe063a30da70a3313

                  En last thing, I do use UnmanagedExport version 1.2.7.

                  1 Reply Last reply Reply Quote 0
                  • Kasper GraversenK
                    Kasper Graversen
                    last edited by

                    hi all I’ve released https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/releases/tag/0.93.87 but @greenzest comment perhaps reveals another version should be released soon? ;)

                    1 Reply Last reply Reply Quote 0
                    • greenzestG
                      greenzest
                      last edited by

                      Hello @Kasper-Graversen ,

                      As fas as I can tell (I didn’t try your version!) you will have the following problems with your version :

                      • Your plugin will register its functions array but you will not correctly receive the notifications from npp/scintilla (all header.code will be at 0)
                      • Calls to sendmessage might cause the program to freeze as stated in the pinvoke page :
                      2) NEVER use "int" or "integer" as lParam. Your code WILL crash on 64-bit windows. ONLY use IntPtr, a "ref" structure, or an "out" structure.
                      
                      3) NEVER use "bool", "int", or "integer" as the return value. Your core WILL crash on 64-bit windows. ONLY use IntPtr. It's not safe to use bool - pInvoke cannot marshal an IntPtr to a boolean.
                      

                      regards

                      1 Reply Last reply Reply Quote 0
                      • Kasper GraversenK
                        Kasper Graversen
                        last edited by

                        This code has been taken over by UFO but I really never found the time to really get into it. You are more than welcome to fix the code. My interest is for the moment merely to be able to compile my plugins with VS2015.

                        After discussing with the author of Scintilla and not being able to reach the author of N++ it seems no one is interested in cleaning up the zest pool of mess called the api to N++ and Scintilla. A lot of really nice stuff could come out of taking a more structured/generative approach benefiting plugin packs of all languages. But no interest is to be traced from those authors…

                        1 Reply Last reply Reply Quote 0
                        • Kasper GraversenK
                          Kasper Graversen
                          last edited by

                          @greenzest said:

                          I think the latest merged pull request takes care of this https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/commit/a9c44746380ca3af7a147a5466342c632e2b0d80
                          happy to hear your thoughts :)

                          1 Reply Last reply Reply Quote 0
                          • Kasper GraversenK
                            Kasper Graversen
                            last edited by

                            Just released a new and improved 64bit version https://github.com/kbilsted/NotepadPlusPlusPluginPack.Net/releases

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors