public partial class Main : Window
{
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
}
}
[/code] 新手上路,基础不好,做毕业设计,还请多多指教。 第一个错误是错误 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 ————————————————————————– |
|
![]() |
分别是43和51行报错
|
![]() 10分 |
1,: 是参数无效。 调用方法 传递的参数类型可能错误。
2 : 错误提示很明显了。 转换错误 |
![]() 20分 |
[DllImport(“trans.dll”)]
public static extern int transmain(string exportpath,string importpath); 用string |
![]() |
这是调用的DLL,外部调用时,要求用char*。。。。。。。。。。。。 |
![]() |
其实是一个问题,把2中的类型转换了之后,就可以把正确的参数传输给函数了。。。 |
![]() 30分 |
不一定要用char* 如果c里面是char * 那C#里面可以用string 或StringBuider这两个。 |
![]() 30分 |
是ToCharArray()方法吧 |
![]() 10分 |
char*
确认这不是C++? |
![]() |
什么意思,调用DLL里的外部函数,必须要char*型的参数啊。。。你的意思,我不太明白。 |
![]() |
这个C#里引用了c++为源代码的DLL,DLL的外部调用函数需要char*型参数。。。您看,怎么把string变成char* |
![]() |
如图,就是这个问题。 |

