110,577
社区成员
发帖
与我相关
我的任务
分享
namespace WpfApplication2
{
class MyClass1 : INotifyPropertyChanged
{
public MyClass1()
{
result="null";
}
private string result;
public string Result
{
get { return result; }
set { result = value;
if (PropertyChanged != null)
{
this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Result"));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public class mytransdll
{
[DllImport("mytransdll.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern int mytransfunc(StringBuilder exportpath, StringBuilder importpath);
}
public partial class Main : Window
{
MyClass1 myout=new MyClass1 ();
private StringBuilder exportpath;
private StringBuilder importpath;
public Main()
{
InitializeComponent();
myout.Result = "there will show ,if transform is ok ";// Result 赋值应该放到Main的构造函数或者窗口的Loaded事件中赋值的。
//把结果binding上去。。。请注意,XAML里的binding并不能访问C#里的变量,而C#里的变量却可以访问XAML
Binding bind1 = new Binding();
bind1.Source = myout;
bind1.Path = new PropertyPath("Result");
this.MyLabel.SetBinding(Label.ContentProperty, bind1);
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
//int isornotsuccess = 1;
int isornotsuccess = mytransdll.mytransfunc(exportpath, importpath);
myout.Result = " Transforming,please wait....";
Binding bind3 = new Binding();
bind3.Source = myout;
bind3.Path = new PropertyPath("Result");
this.MyLabel.SetBinding(Label.ContentProperty, bind3); //按下按钮之后马上显示正在传输
if (isornotsuccess == 1)
{
myout.Result = exportpath.ToString() ;
Binding bind2 = new Binding();
bind2.Source = myout;
bind2.Path = new PropertyPath("Result");
this.MyLabel.SetBinding(Label.ContentProperty, bind2); //这里写成功后的反应
}
}
private void textBox1_KeyDown_1(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter) //key是一个类,这是一个类的判断
{
StringBuilder exportpath=new StringBuilder(this.textBox1.Text,200);
}
}
//
#include "stdafx.h"
#include "stdio.h"
#include"pcap.h"
#include<WinSock.h>
#include"packet32.h"
#include<Win32-Extensions.h>
#include "stdlib.h"
extern "C" _declspec(dllimport) int mytransfunc(char* exportpath,char* importpath);
int mytransfunc(char* exportpath,char* importpath)
{
//和EXPORTPATH无关的代码
char A[]="regenerate_original_picture.txt";
char PA[1024];
char exportpathvalue=*exportpath;
//!!!!高能,就是这句出问题。不管是用这种方法中转还是直接调用*exportpath都出现报错
sprintf(PA,"%s\\%s",exportpathvalue,A);//连接字符串
FILE *fpopen = fopen(PA, "rb");
//和EXPORTPATH无关的代码
}