flat assembler
Message board for the users of flat assembler.

Index > Examples and Tutorials > Basic Notepad++ Plugin

Author
Thread Post new topic Reply to topic
bitRAKE



Joined: 21 Jul 2003
Posts: 2936
Location: vpcmipstrm
bitRAKE
All the C++ abstractions might make writing plugins for Notepad++ seem difficult in assembly. Here is a basic template to get started:
Code:
INCLUDE 'win64w.inc'
FORMAT PE64 GUI 5.0 DLL AT 0
SECTION '.text' CODE READABLE EXECUTABLE

DllMain: ENTRY $
        cmp edx,DLL_PROCESS_ATTACH
        jnz .x
        mov [hInstance],rcx

        ; dynamic setup

.x:     push 1
        pop rax
        retn


; REFERENCES:
;       Although these files are in the plugin kit, main is most recent:
;       https://github.com/notepad-plus-plus/notepad-plus-plus/
;               /PowerEditor/src/menuCmdID.h
;               /PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h
;               /scintilla/include/Scintilla.h
;       etc.

isUnicode: ; BOOL isUnicode();
        push 1                          ; npp always UNICODE compiled
        pop rax                         ; always true
        retn


getName: ; const TCHAR * getName()
        lea rax,[PluginName]
        retn


; NOTE: remove the indirection so the handles can be used directly
setInfo: ; void setInfo(NppData notpadPlusData)
        push qword [rcx]
        push qword [rcx+8]
        push qword [rcx+16]
        pop [scintillaSecondHandle]
        pop [scintillaMainHandle]
        pop [nppHandle]
        retn


beNotified: ; void beNotified(SCNotification *notifyCode)
        retn


messageProc: ; LRESULT messageProc(UINT /*Message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
        retn


getFuncsArray: ; FuncItem * getFuncsArray(int *nbF)
        lea rax,[Functions]
        mov dword[rcx],nbFunc
        retn

;GetLexerCount:
;GetLexerName:
;GetLexerStatusText:


Name_A:
        retn


Name_B:
        retn


SECTION '.data' DATA READABLE WRITEABLE

PluginName du "TestPlugin",0

macro FuncItem text,func,id=0,chk=0,key=0
        local temp
temp    du text
        rw 64 - (($ - temp) shr 1)
        dq func ;
        dd id
        db chk,?,?,?
        if key=0
                dq 0
        else
                ; point to ShortcutKey structure
        end if
end macro
FuncItem.bytes = 152 ; 128+8+4+4+8

align 64
Functions:
        FuncItem "Name A",      Name_A
        FuncItem "-SEPARATOR-", 0
        FuncItem "Name B",      Name_B
nbFunc = ($-Functions)/FuncItem.bytes



hInstance rq 1
nppHandle rq 1
scintillaMainHandle rq 1
scintillaSecondHandle rq 1



;SECTION '.idata' IMPORT DATA READABLE WRITEABLE

;  library kernel32,'KERNEL32.DLL',\
;         user32,'USER32.DLL'

;  include 'api\kernel32.inc'
;  include 'api\user32.inc'

SECTION '.edata' EXPORT DATA READABLE
export 'plugtest.dll',\
        beNotified      ,"beNotified",\
        getFuncsArray   ,"getFuncsArray",\
        getName         ,"getName",\
        isUnicode       ,"isUnicode",\
        messageProc     ,"messageProc",\
        setInfo         ,"setInfo"
;GetLexerCount          ,"GetLexerCount",\
;GetLexerName           ,"GetLexerName",\
;GetLexerStatusText     ,"GetLexerStatusText"

SECTION '.reloc' FIXUPS DATA READABLE DISCARDABLE    
Installation requires quiting Notepad++, and putting the DLL in a folder within the plugins directory. Typically: "C:\Program Files\Notepad++\plugins\"

The functions isUnicode, getName, setInfo, and getFuncsArray; are basically constant. Only the functions in the array returned by getFuncsArray, beNotified and messageProc effect operation of the plugin.

_________________
¯\(°_o)/¯ unlicense.org
Post 16 May 2020, 11:42
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2936
Location: vpcmipstrm
bitRAKE
No reason not to use the direct call interface on the Scintilla control:
Code:
; NOTE: remove the indirection so the handles can be used directly
setInfo: ; void setInfo(NppData notpadPlusData)
        push qword [rcx]
        push qword [rcx+8]
        push qword [rcx+16]
        pop [scintillaSecondHandle]
        pop [scintillaMainHandle]
        pop [nppHandle]

        enter 32,0

        xor r9,r9
        xor r8,r8
        mov edx,SCI_GETDIRECTFUNCTION
        mov rcx,[scintillaMainHandle]
        call[SendMessageW]
        mov [CallScintilla],rax

        xor r9,r9
        xor r8,r8
        mov edx,SCI_GETDIRECTPOINTER
        mov rcx,[scintillaMainHandle]
        call[SendMessageW]
        mov [CallScintilla.windows],rax

        xor r9,r9
        xor r8,r8
        mov edx,SCI_GETDIRECTPOINTER
        mov rcx,[scintillaSecondHandle]
        call[SendMessageW]
        mov [CallScintilla.windows+8],rax

        leave
        retn


; use direct call interface
;       view: reg64, [memory] or literal 0 or 1
;       msg: messages defined in Scintilla documentation
;       lp,wp: parameters, support ADDR for address calculation
macro sciCall view*,msg*,lp=0,wp=0
        iterate <R,P>, R8,lp, R9,wp
                match =0,P
                        xor R,R
                else match =ADDR? M,P
                        lea R,M
                else match =R,R
                        ; do nothing is an option
                else
                        mov R,P
                end match
        end iterate
        mov edx,msg
        match [M],view
                movzx ecx,byte[M]
                mov rcx,[CallScintilla.windows + rcx*8]
        else
                mov rcx,[CallScintilla.windows + view*8]
        end match
        call [CallScintilla]
end macro    
; direct pointer interface:
CallScintilla rq 1
.windows rq 2 ; npp currently only has two Scintilla windows

...and I left out the two most important links:

https://github.com/notepad-plus-plus/npp-usermanual/blob/master/content/docs/plugin-communication.md

https://www.scintilla.org/ScintillaDoc.html

Wink

_________________
¯\(°_o)/¯ unlicense.org
Post 17 May 2020, 22:54
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.