YuO様、返信ありがとうございます。
教えていただいたリンクを元に、MeCab.NETを使用しない以下のコードを作成してみました。
コード:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MeCab_Test
{
public partial class Form1 : Form
{
[DllImport("libmecab.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static IntPtr mecab_new2(string arg);
[DllImport("libmecab.dll", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.AnsiBStr)]
private extern static string mecab_sparse_tostr(IntPtr m, string str);
[DllImport("libmecab.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static void mecab_destroy(IntPtr m);
public Form1()
{
InitializeComponent();
}
//button1クリックイベント
private void button1_Click(object sender, EventArgs e)
{
label1.Text = Wakati("テストです");
}
//わかち解析
private string Wakati(string str)
{
IntPtr mecab = mecab_new2("-O wakati");
string s = mecab_sparse_tostr(mecab, str); //ここで終了してしまいます。
mecab_destroy(mecab);
return s;
}
}
}
が、これでもやはりプログラムが終了してしまいます。
libmecab.dllは、このプログラムのbinフォルダにコピーしています。
OSが64bitなのが関係しているのでしょうか?
※MeCabはProgram Files (x86)ではなく、C:\Program Files\MeCab内にインストールしています。