private void button_call_Click(object sender, RoutedEventArgs e) { if (imgFile != "") { ListBoxItem selected = (ListBoxItem)listBox.SelectedItem; if (selected == null) { listBox.SelectedIndex = 0; selected = (ListBoxItem)listBox.SelectedItem; } if (selected == null) { return; } string s = selected.Content.ToString(); if (loadedPlugins.ContainsKey(s)) { IntPtr hModule = loadedPlugins[s]; FnProcess fnProcess = (FnProcess)PluginDllUtils.GetProcDelegate(hModule, "Process", typeof(FnProcess)); if (fnProcess(imgFile) == 1)//succeeded { imgFile = imgFile.Substring(0, imgFile.Length - 4) + "_processed.bmp"; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.UriSource = new Uri(imgFile, UriKind.Absolute); bitmap.EndInit(); image.Source = bitmap; Title = imgFile; } } } }
private void button_load_Click(object sender, RoutedEventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "plugin dll(*.dll) | *.dll"; openFileDialog.FilterIndex = 1; openFileDialog.RestoreDirectory = true; string selected = ""; if (openFileDialog.ShowDialog() != true) { return; } selected = openFileDialog.FileName; IntPtr hModule = PluginDllUtils.LoadLibrary(selected); if (hModule == IntPtr.Zero) { return; } string pluginName = PluginDllUtils.GetPluginName(hModule); if (pluginName == null || pluginName.Substring(0, 5) != "PIMG_") { PluginDllUtils.FreeLibrary(hModule); return; } foreach (ListBoxItem item in listBox.Items) { string s = item.Content.ToString(); if (s == pluginName) { PluginDllUtils.FreeLibrary(hModule); return; } } ListBoxItem newItem = new ListBoxItem(); newItem.Content = pluginName; listBox.Items.Add(newItem); loadedPlugins[pluginName] = hModule; }