R
R
romserg2019-09-20 22:14:23
Delphi
romserg, 2019-09-20 22:14:23

Notepad++, Scintilla, SendMessages and Delphi - how to insert a line?

Hello, I'm having trouble managing Scintilla in n++ via messages. I am using delphi.
I get handle skintills through FindWindow and FindWindowEx.
I'm trying to pass a replacement string like this:
str:='qwerty'#0;
sendmessage(hwndScintilla,2170,0, lparam(pchar(str)) );
2170 is SCI_REPLACESEL. I don't include header files, so I just use numbers instead of constants.
But instead of the passed string, this one appears:
K6c8b5L3YLBpTIEwj8Q_AN1BfZTxZS5BG9vspHPN
And every time you restart n++ and my program, "this" is always different.
And messages that return numbers work fine:
sendmessage(hwndScintilla,2143,0,0 )
2143 is SCI_GETSELECTIONSTART.
How do I pass a replacement string to Scintilla?
Documentation from here:https://www.scintilla.org/ScintillaDoc.html#SCI_RE...
Constants here: freesourcecode.net/cprojects/106750/sourcecode/Sci...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zed, 2019-09-20
@zedxxx

You pass a pointer to a memory location in your program's address space, and Notepad++ has its own isolated address space. And at the address indicated in the message, of course, there will be garbage.
In order to pass the buffer from application to application, WinAPI provides the WM_COPYDATA message . And in this case, Windows "under the hood" takes care of moving the transmitted buffer into the address space of the destination application so that it can read it.
But Scintilla doesn't expect to be controlled from outside, so you can't directly send such a message to it. You can try to inject your dll into the Notepad++ address space and add the WM_COPYDATA message handler there with forwarding to Scintilla from the inside.
Since Notepad++ supports plugins, there shouldn't be any problems with dll injection. The demo for the Delphi plugin even has an example of how to control Scintilla:

procedure THelloWorldPlugin.FuncHelloWorld;
var
  s: string;
begin
  s := 'Hello World';
  SendMessage(self.NppData.ScintillaMainHandle, SCI_REPLACESEL, 0, LPARAM(PChar(s)));
end;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question