cp866 (DOS) to cp1251 (WIN) conversion

2006-03-03
2012-11-14
  • I have modified example plugin "NppInsertPlugin.dll" and now it simply converts cp866-text to cp1251.

    All you need is the following function:

    void cp866_to_cp1251()
    {
      INT currentEdit;
      ::SendMessage(nppData._nppHandle, WM_GETCURRENTSCINTILLA, 0, (LPARAM)&currentEdit);
      INT nTextLength =
        (INT) ::SendMessage(getCurrentHScintilla(currentEdit), SCI_GETTEXTLENGTH, 0, 0);
      TCHAR* textbuf = new TCHAR[nTextLength+2];
      if (textbuf == NULL)
        return;
      ::SendMessage(getCurrentHScintilla(currentEdit),
        SCI_GETTEXT, (WPARAM) nTextLength, (LPARAM) textbuf);
      // ... modifying textbuf ...
      OemToChar(textbuf, textbuf);
      ::SendMessage(getCurrentHScintilla(currentEdit),
        SCI_SETTEXT, (WPARAM) 0, (LPARAM) textbuf);
      delete [] textbuf;
    }

     
    • Oh, you did great work! OemToChar(textbuf, textbuf);
      LOL