为类型库(Type Library)生成帮助文件
在昨天的随笔中给出了一个查看类型库(Type Library)详细信息的工具的实现方法,今天又添加了为类型库自动生成帮助文件的功能。
主要是调用Codestone Ltd提供的tlbdoc.exe,偶然在网上发现的一个好东东,它可以为Type Library生成Windows帮助文件:
增加的“生成帮助”功能:
具体实现:
1 private void btnGenHelp_Click(object sender, System.EventArgs e)
2 {
3 if (this.lvTL.SelectedItems.Count == 0)
4 return;
5
6 string strGUID = this.lvTL.SelectedItems[0].SubItems[2].Text;
7 string strVersion = this.lvTL.SelectedItems[0].SubItems[1].Text;
8
9 TypeLibBrowser.TypeLib tlbDetail = this.tlbList.GetTLDetail(strGUID, strVersion);
10
11 string strFirstFile = "";
12
13 if (tlbDetail.Files != null)
14 {
15 foreach(TypeLibBrowser.TLBFile tlbFile in tlbDetail.Files)
16 {
17 strFirstFile = tlbFile.File;
18 break;
19 }
20 }
21
22 if (strFirstFile != null && strFirstFile != String.Empty)
23 {
24 try
25 {
26 System.Diagnostics.ProcessStartInfo psiGenHelp = new System.Diagnostics.ProcessStartInfo();
27 //调用tlbdoc.exe生成帮助文件
28 psiGenHelp.FileName = System.Windows.Forms.Application.StartupPath + @"\tlbdoc.exe";
29 psiGenHelp.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
30 try
31 {
32 //设置当前进程工作目录,注意可能会出现System.IO.Path.GetDirectoryName(strFirstFile)为空
33 System.Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(strFirstFile);
34 //为tlbdoc.exe指定参数
35 psiGenHelp.Arguments = System.IO.Path.GetFileName(strFirstFile) + " /c /r";
36 }
37 catch
38 {
39 psiGenHelp.Arguments = strFirstFile + " /c /r";
40 }
41 System.Diagnostics.Process proGenHelp = System.Diagnostics.Process.Start(psiGenHelp);
42 proGenHelp.Close();
43 }
44 catch
45 {
46 System.Windows.Forms.MessageBox.Show("生成帮助文件时发生了一个错误!", "提示");
47 }
48 }
49 }
2 {
3 if (this.lvTL.SelectedItems.Count == 0)
4 return;
5
6 string strGUID = this.lvTL.SelectedItems[0].SubItems[2].Text;
7 string strVersion = this.lvTL.SelectedItems[0].SubItems[1].Text;
8
9 TypeLibBrowser.TypeLib tlbDetail = this.tlbList.GetTLDetail(strGUID, strVersion);
10
11 string strFirstFile = "";
12
13 if (tlbDetail.Files != null)
14 {
15 foreach(TypeLibBrowser.TLBFile tlbFile in tlbDetail.Files)
16 {
17 strFirstFile = tlbFile.File;
18 break;
19 }
20 }
21
22 if (strFirstFile != null && strFirstFile != String.Empty)
23 {
24 try
25 {
26 System.Diagnostics.ProcessStartInfo psiGenHelp = new System.Diagnostics.ProcessStartInfo();
27 //调用tlbdoc.exe生成帮助文件
28 psiGenHelp.FileName = System.Windows.Forms.Application.StartupPath + @"\tlbdoc.exe";
29 psiGenHelp.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
30 try
31 {
32 //设置当前进程工作目录,注意可能会出现System.IO.Path.GetDirectoryName(strFirstFile)为空
33 System.Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(strFirstFile);
34 //为tlbdoc.exe指定参数
35 psiGenHelp.Arguments = System.IO.Path.GetFileName(strFirstFile) + " /c /r";
36 }
37 catch
38 {
39 psiGenHelp.Arguments = strFirstFile + " /c /r";
40 }
41 System.Diagnostics.Process proGenHelp = System.Diagnostics.Process.Start(psiGenHelp);
42 proGenHelp.Close();
43 }
44 catch
45 {
46 System.Windows.Forms.MessageBox.Show("生成帮助文件时发生了一个错误!", "提示");
47 }
48 }
49 }
源码下载:DOWN
Life is like a boat, and I'm at sea.