int start = (int)Win32.SendMessage(hCurrScintilla, SciMsg.SCI_GETSELECTIONSTART, 0, 0); int end = (int)Win32.SendMessage(hCurrScintilla, SciMsg.SCI_GETSELECTIONEND, 0, 0); int textLen = end - start; StringBuilder sb = new StringBuilder(textLen + 1); Win32.SendMessage(hCurrScintilla, SciMsg.SCI_GETSELTEXT, 0, sb);That works fine with ASCII string but not binary data, because StringBuilder object truncks data due to the 1st NULL character. I'm sure that SCI_GETSELTEXT copies the whole data (with NULL characters) since I did it in ASCII/Hex converter plugin (in C++). Have you any idea to get the selected binary data by using nppPlugin.NET? Don
IntPtr hCurrScintilla = PluginBase.GetCurrentScintilla();
int textLen = (int)Win32.SendMessage(hCurrScintilla, SciMsg.SCI_GETSELTEXT, 0, 0);
IntPtr ptrText = Marshal.AllocHGlobal(textLen);
Win32.SendMessage(hCurrScintilla, SciMsg.SCI_GETSELTEXT, 0, ptrText);
// get it as string but truncated..
string s = Marshal.PtrToStringAnsi(ptrText);
// or everything.. well as byte array
byte[] b = new byte[textLen];
Marshal.Copy(ptrText, b, 0, textLen);
Marshal.FreeHGlobal(ptrText);
greets
public static class NppNotification
{
public static event NppNotificationEvent Ready;
public static event NppNotificationEvent TBModification;
public static event NppNotificationEvent FileBeforeClose;
public static event NppNotificationEvent FileClosed;
public static event NppNotificationEvent FileBeforeOpen;
public static event NppNotificationEvent FileOpened;
public static event NppNotificationEvent FileBeforeSave;
public static event NppNotificationEvent FileSaved;
public static event NppNotificationEvent Shutdown;
public static event NppNotificationEvent BufferActivated;
public static event NppNotificationEvent LangChanged;
public static event NppNotificationEvent WordStylesUpdated;
public static event NppNotificationEvent ShortcutRemapped;
public static event NppNotificationEvent FileBeforeLoad;
public static event NppNotificationEvent FileLoadFailed;
public static event NppNotificationEvent DocOrderChanged;
internal static void Process(SCNotification nc)
{
switch(nc.nmhdr.code)
{
case (uint)NppMsg.NPPN_DOCORDERCHANGED:
if (DocOrderChanged != null)
DocOrderChanged(nc);
break;
case (uint)NppMsg.NPPN_FILEBEFORELOAD:
if (FileBeforeLoad != null)
FileBeforeLoad(nc);
break;
case (uint)NppMsg.NPPN_SHORTCUTREMAPPED:
if (ShortcutRemapped != null)
ShortcutRemapped(nc);
break;
case (uint)NppMsg.NPPN_WORDSTYLESUPDATED:
if (WordStylesUpdated != null)
WordStylesUpdated(nc);
break;
case (uint)NppMsg.NPPN_LANGCHANGED:
if (LangChanged != null)
LangChanged(nc);
break;
case (uint)NppMsg.NPPN_BUFFERACTIVATED:
if (BufferActivated != null)
BufferActivated(nc);
break;
case (uint)NppMsg.NPPN_FILEBEFORESAVE:
if (FileSaved != null)
FileSaved(nc);
break;
case (uint)NppMsg.NPPN_FILEOPENED:
if (FileOpened != null)
FileOpened(nc);
break;
case (uint)NppMsg.NPPN_FILEBEFOREOPEN:
if (FileBeforeOpen != null)
FileBeforeOpen(nc);
break;
case (uint)NppMsg.NPPN_FILECLOSED:
if (FileClosed != null)
FileClosed(nc);
break;
case (uint)NppMsg.NPPN_TBMODIFICATION:
if (TBModification != null)
TBModification(nc);
break;
case (uint)NppMsg.NPPN_READY:
if (Ready != null)
Ready(nc);
break;
case (uint)NppMsg.NPPN_SHUTDOWN:
if (Shutdown != null)
Shutdown(nc);
break;
case (uint)NppMsg.NPPN_FILEBEFORECLOSE:
if (FileBeforeClose != null)
FileBeforeClose(nc);
break;
}
}
}
public delegate void NppNotificationEvent(SCNotification nc);
and then in UnmanagedExports.cs:
[DllExport(CallingConvention = CallingConvention.Cdecl)]
static void beNotified(IntPtr notifyCode)
{
SCNotification nc = (SCNotification)Marshal.PtrToStructure(notifyCode, typeof(SCNotification));
NppNotification.Process(nc); //process the notification to fire off the associated event
if (nc.nmhdr.code == (uint)NppMsg.NPPN_TBMODIFICATION)
{
PluginBase._funcItems.RefreshItems();
Main.SetToolBarIcon();
}
else if (nc.nmhdr.code == (uint)NppMsg.NPPN_SHUTDOWN)
{
Main.PluginCleanUp();
Marshal.FreeHGlobal(_ptrPluginName);
}
}
internal static void SetupDomain()
{
Assembly pluginAssembly = Assembly.GetExecutingAssembly();
string pluginPath = pluginAssembly.Location;
string pluginName = Path.GetFileNameWithoutExtension(pluginPath);
string pluginSubFolder = Path.Combine(Path.GetDirectoryName(pluginPath), pluginName);
AppDomain.CurrentDomain.AppendPrivatePath(pluginSubFolder);
}
Now you can place your referenced stuff into a subfolder, which has the same name
as your plugin. If your main DLL is called "MyPlugin.dll", then your subfolder should
be called "MyPlugin". It's a sensemaking but unwritten (?) convention followed by
myself and other plugin authors aswell.
Of course there's still the warning CS0618. I personally add following at top of the source file:
#pragma warning disable 618
cheers
This forum does not allow anonymous participation.
Log in to add a reply. Not registered? Create an account to participate and receive email updates when replies are posted to this topic.