[DllImport(Libraries.Bundle, EntryPoint = "bundle_foreach")]
internal static extern void Foreach(IntPtr handle, Iterator iterator, IntPtr userData);
+ [DllImport(Libraries.Bundle, EntryPoint = "bundle_dup")]
+ internal static extern IntPtr Clone(IntPtr handle);
+
internal static class UnsafeCode
{
internal static unsafe int AddItem(IntPtr handle, string key, byte[] value, int offset, int count)
}
_messageCallBack = (int localPortId, string remoteAppId, string remotePortName, bool trusted, IntPtr message, IntPtr userData) =>
{
- MessageReceivedEventArgs args = new MessageReceivedEventArgs()
- {
- Message = new Bundle(message)
+ MessageReceivedEventArgs args = new MessageReceivedEventArgs() {
+ Message = Bundle.MakeRetainedBundle(message)
};
if (!String.IsNullOrEmpty(remotePortName) && !String.IsNullOrEmpty(remoteAppId))
string value = b.GetItem<string>(Interop.AppEvent.EventKeys.LanguageSet);
OnLocaleChanged(new LocaleChangedEventArgs { Locale = value });
}
+ b.Dispose();
}
}
}
_keys = new HashSet<string>();
}
- internal Bundle(IntPtr handle)
+ static internal Bundle MakeRetainedBundle(IntPtr handle)
+ {
+ IntPtr clonedHandle = Interop.Bundle.Clone(handle);
+ return new Bundle(clonedHandle, true);
+ }
+
+ internal Bundle(IntPtr handle, bool ownership = false)
{
if (handle != IntPtr.Zero)
{
_handle = handle;
- _disposed = true;
+ if (!ownership)
+ _disposed = true;
_keys = new HashSet<string>();
Interop.Bundle.Iterator iterator = (string key, int type, IntPtr keyval, IntPtr userData) =>
{