public partial class Main : Window[/code]
{
private char* exportpath;
private char* importpath;
public Main()
{
InitializeComponent();
}
public class trans
{
[DllImport("trans.dll")]
public static extern int transmain(char* exportpath,char* importpath);
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
//创建"打开文件"对话框
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
//设置文件类型过滤
dlg.Filter = "图片|*.jpg;*.png;*.gif;*.bmp;*.jpeg";
// 调用ShowDialog方法显示"打开文件"对话框
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
//获取所选文件名并在FileNameTextBox中显示完整路径
string filename = dlg.FileName;
//在image1中预览所选图片
BitmapImage image = new BitmapImage(new Uri(filename));
image1.Source = image;
//image1.Width = image.Width;
//image1.Height = image.Height;
//这段代码可以预览图片
}
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
int isornotsuccess = trans.transmain(*exportpath, *importpath);
}
private unsafe void textBox1_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter) //key是一个类,这是一个类的判断
{
export=this.textBox1.Text;
char *exportpath = export.ToArray(); //把EXPORT 由string转换成char
}
}
新手上路,基础不好,做毕业设计,还请多多指教。
第一个错误是错误 3 与“WpfApplication2.Main.trans.transmain(char*, char*)”最匹配的重载方法具有一些无效参数 C:\Users\Frank\Documents\Visual Studio 2012\Projects\WPFforjiekouchengxu\WpfApplication2\Main.xaml.cs 90 34 WpfApplication2
第二个错误是错误 6 无法将类型“char[]”隐式转换为“char*” C:\Users\Frank\Documents\Visual Studio 2012\Projects\WPFforjiekouchengxu\WpfApplication2\Main.xaml.cs 98 37 WpfApplication2
--------------------------------------------------------------------------
请高手修改
------解决思路----------------------
1,: 是参数无效。 调用方法 传递的参数类型可能错误。
2 : 错误提示很明显了。 转换错误
------解决思路----------------------
[DllImport("trans.dll")]
public static extern int transmain(string exportpath,string importpath);
用string
------解决思路----------------------
不一定要用char* 如果c里面是char * 那C#里面可以用string 或StringBuider这两个。
------解决思路----------------------
[DllImport("trans.dll")]
public static extern int transmain(string exportpath,string importpath);
用string
这是调用的DLL,外部调用时,要求用char*。。。。。。。。。。。。
能不能再C#里转换类型呢?我看了些其他的帖子,那些方法比如toarray()什么的,居然都在这里找不到定义。。。求助
是ToCharArray()方法吧
------解决思路----------------------
char*
确认这不是C++?