[英]How to use builder and stub in WPF C#
I try to build an application using a builder and a stub but i fail 我尝试使用生成器和存根构建应用程序,但失败了
My builder code : 我的生成器代码:
File.Copy(AppDomain.CurrentDomain.BaseDirectory + @"\Camstub.exe", filepath);
string split = "|";
string info = split + CName.Text + split + Link.Text + split;
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
BinaryWriter bw = new BinaryWriter(fs);
fs.Position = fs.Length + 1;
bw.Write(info);
bw.Close();
MessageBox.Show(info);
My stub code : 我的存根代码:
public MainWindow()
{
InitializeComponent();
StreamReader sr = new StreamReader(System.Windows.Forms.Application.ExecutablePath);
BinaryReader br = new BinaryReader(sr.BaseStream);
byte[] fileData = br.ReadBytes(Convert.ToInt32(sr.BaseStream.Length));
br.Close();
sr.Close();
ASCIIEncoding Enc = new ASCIIEncoding();
string split = "|";
string Message = Enc.GetString(fileData);
MessageBox.Show(Message);
The messagebox in the builder show me: 生成器中的消息框显示给我:
The application is sucessfully build but the messagebox when i execute it show me: 该应用程序已成功构建,但执行我时显示的消息框显示:
So, I expect the same messagebox in both. 因此,我希望两者都具有相同的消息框。
Any idea ? 任何想法 ?
Thanks in advance ;) 提前致谢 ;)
Based on the information given in the comments, you want to read the |CName|Link| 根据注释中给出的信息,您想阅读| CName | Link |。 data from the end of the file.
文件末尾的数据。 The |CName|Link|
| CName | Link | data can be of variable length.
数据可以具有可变长度。
To deal with variable length data you somehow need to indicate the byte length of the data. 为了处理可变长度的数据,您需要以某种方式指示数据的字节长度。 In the given scenario here, a simple and suitable solution would be to store the byte length as a 2-byte or 4-byte number at the end of the file after the |CName|Link|
在给定的情况下,一个简单而合适的解决方案是将字节长度存储为| CName | Link |之后的文件末尾的2字节或4字节数字。 data.
数据。 A 2-byte number (ie, ushort or UInt16 ) allows to specify a length of up to 65536 and should likely be sufficient for your purpose.
一个2字节的数字(即ushort或UInt16 )允许指定一个最大长度为65536的长度,并且应该足以满足您的目的。 (If the data can be more than 64KB, then use 4 bytes to store the length.)
(如果数据可以大于64KB,则使用4个字节存储长度。)
Thus, the builder should do the following: 因此,构建器应执行以下操作:
The stub should do something like this: 存根应执行以下操作:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.