Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 141025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:42:36+00:00 2026-05-11T07:42:36+00:00

I’m attempting to retrieve the document text in Notepad++ using SendMessage in C#. Below

  • 0

I’m attempting to retrieve the document text in Notepad++ using SendMessage in C#. Below is my current code. The first call to SendMessage correctly returns the length of the text. The second call to SendMessage does not insert the text into the StringBuilder variable text. Why not?

    [DllImport('user32.dll', EntryPoint = 'SendMessage', CharSet = CharSet.Auto)]     static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);      [DllImport('user32.dll', EntryPoint = 'SendMessage', CharSet = CharSet.Auto)]     static extern int SendMessage(IntPtr hWnd, int msg, int wParam, StringBuilder lParam);       var length = SendMessage(hWnd, 2183, 0,0);     var text = new StringBuilder(length +1);     SendMessage(hWnd, 2182, length + 1, text); 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:42:37+00:00Added an answer on May 11, 2026 at 7:42 am

    The problem is that you send a message to the Scintilla control that has the address of your StringBuilder buffer in the lParam, but the Scintilla control in Notepad++ lives in a different address space, so the address in the window message it receives can not be written to. Standard messages like WM_GETTEXT and WM_SETTEXT are handled in a way that the necessary address mapping is performed for you, but this does not happen for the special messages the Scintilla control uses. For more information lookup marshalling.

    Unfortunately support for WM_GETTEXTLENGTH and WM_GETTEXT is being phased out of the Scintilla control, and the documentation advises to use the special SCI_XXX messages. Notepad++ does already not work with WM_GETTEXT, so you need to use SCI_GETTEXTLENGTH (2183) and SCI_GETTEXT (2182), and do the marshalling yourself.

    Warning: It is actually dangerous to send the SCI_GETTEXT message from another application without special handling of the buffer address – Notepad++ will copy the data to the buffer, but since the address is not valid in its own address space this can cause an access violation immediately, or (worse) it could silently overwrite internal data.


    You can use VirtualAllocEx() and ReadProcessMemory() to use a buffer with an address usable by Notepad++. I have put together a quick Delphi program that works for me, the important code is this:

    procedure TForm1.Button1Click(Sender: TObject); const   VMFLAGS = PROCESS_VM_OPERATION or PROCESS_VM_READ or PROCESS_VM_WRITE; var   Wnd: HWND;   Len: integer;   ProcessId, BytesRead: Cardinal;   ProcessHandle: THandle;   MemPtr: PChar;   s: string; begin   Wnd := $30488;   Len := SendMessage(Wnd, 2183, 0, 0);   if Len > 0 then begin     GetWindowThreadProcessId(Wnd, @ProcessId);     ProcessHandle := OpenProcess(VMFLAGS, FALSE, ProcessId);     MemPtr := VirtualAllocEx(ProcessHandle, nil, Len + 1,       MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);     if MemPtr <> nil then try       SendMessage(Wnd, 2182, Len + 1, integer(MemPtr));       SetLength(s, Len + 1);       ReadProcessMemory(ProcessHandle, MemPtr, @s[1], Len + 1, BytesRead);       SetLength(s, BytesRead);       Memo1.Lines.Text := s;     finally       VirtualFreeEx(ProcessId, MemPtr, Len + 1, MEM_RELEASE);     end;   end; end; 

    This is an earlier Delphi version using the Ansi version of the API functions, you would probably use SendMessageW and a WideChar buffer, but the general idea should be clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What's the problem with adding a listener? That's what they… May 16, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer If the checkbox isn't ticked then nothing is sent to… May 16, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer There is nothing inherently wrong in the code you have… May 16, 2026 at 5:10 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.