- tlb文件:com类型库文件,它包含接口相关信息。在需要使用对应com类的模块里,通过"#import xxx.tlb"来调用。
- dll: 动态连接库,它包含二进制代码,资源... , VC可以把tlb作为资源编译到dll中。
1.生成TLB文件
选择项目->右键属性->生成->输出->勾选 “为COM互操作注册” 即可生成.tlb文件
去掉勾选 “为COM互操作注册”就不会生成.tlb文件了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using WK_PrintS;
namespace ComManager
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
[ComVisible(true)]
[Guid("E54258BC-E83C-4B06-8B4D-8F78158CAABE")]
public interface IPrintS
{
void frmPrints(string BQID, string BMID);
void Test();
}
[Guid("9EB1363F-5A28-4B0A-BF1C-AEDBE43CC740")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ComManager")]
[ComVisible(true)]
public class PrintS : IPrintS
{
public void frmPrints(string BQID, string BMID)
{
frmPrints dlg = new frmPrints(BQID, BMID);
dlg.ShowDialog();
}
public void Test()
{
System.Windows.Forms.MessageBox.Show("Test");
}
}
}