Upadte: .net Framework 3.5以下を使用していたときに発生したことがわかりましたが、 .net Framework 3.5を使用する必要があります。
ファイルを分析するc DLLがあります。
ファイルを開き、DLL にファイル パスを送信して結果を表示する C# Windows フォームを作成しました。私は WPF を使用する必要があり、コードを変更せずに同じWPFを作成しました。しかし、DLL は間違った結果を返します。
Webで検索していますが、答えが見つかりません。
Windows フォーム コード:
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
static string cascade_name_face = "cascade_name_face.xml";
static string cascade_name_face2 = "cascade_name_face2.xml";
[DllImport("aref_video_score", CallingConvention = CallingConvention.Cdecl)]
public static extern double aref_video_score(String fileName, int a, String cascade_name_face, String cascade_name_face2);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "All file|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
Address1.Text = dlg.FileName;
}
}
private double video_analyze(string filename)
{
try
{
return aref_video_score(filename, 20, cascade_name_face, cascade_name_face2);
}
catch
{
return -1;
};
}
private void button2_Click(object sender, EventArgs e)
{
if (IsVideo(Address1.Text))
MessageBox.Show("This is a 'Video' and video's scroe is " + video_analyze(Address1.Text).ToString());
}
}
}
WPF コード:
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Linq;
using System.Windows;
namespace WpfApplication7
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
static string cascade_name_face = "cascade_name_face.xml";
static string cascade_name_face2 = "cascade_name_face2.xml";
[DllImport("aref_video_score", CallingConvention = CallingConvention.Cdecl)]
public static extern double aref_video_score(String fileName, int a, String cascade_name_face, String cascade_name_face2);
private void Button_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.Filter = "All file|*.*";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
// Open document
string filename = dlg.FileName;
Address1.Text = filename;
}
}
private double video_analyze(string filename)
{
try
{
return aref_video_score(filename, 20,cascade_name_face, cascade_name_face2);
}
catch
{
return -1;
};
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
if(IsVideo(Address1.Text))
MessageBox.Show("This is a 'Video' and video's scroe is " + video_analyze(Address1.Text).ToString());
}
}
}