Best Practice in Writing a COM-Visible Assembly (C#)
来源:互联网 发布:微商和淘宝哪个好 编辑:程序博客网 时间:2024/06/10 17:19
I summarized some best practice rules in writing a COM-visible assembly according to my recent work.
1. In AssemblyInfo.cs, I wrote two attributes:
[assembly: ComVisible(false)][assembly: Guid("64729ced-7a8d-4c90-af7f-a41725cfe216")]
They indicated I didn’t want all public classes to be COM-visible and I didn’t want Visual Studio to implicitly generate a random GUID as my library ID.
2. I unchecked the “Register for COM interop” box in the project’s Build option because I didn’t want Visual Studio to register the assembly on the build machine.
3. I wrote each COM-visible class like the following example:
[ComVisible(true)][Guid("7884998B-0504-4CBE-9FF9-6BBAA9776188")][ClassInterface(ClassInterfaceType.None)]public class MyClass{}
Here I explicitly declared the class as COM-visible and gave it a GUID as the class ID. Visual Studio would generate a random GUID if I didn’t specify one. I used ClassInterfaceType.None to prevent Visual Studio from generating an interface for the class automatically. The automatic behavior would expose methods which I didn’t want to expose and could introduce unwanted method declarations.
4. I declared an interface for each COM-visible class explicitly like the following example:
[ComVisible(true)][Guid("67F6AA4C-A9A5-4682-98F9-15BDF2246A74")][InterfaceType(ComInterfaceType.InterfaceIsDual)]public interface IMyClass{}
There was no special rule for InterfaceType. It would depend on application needs. And I only declared the methods which I wanted to expose in the interface.
- Best Practice in Writing a COM-Visible Assembly (C#)
- Writing a boot loader in Assembly and C
- 编写COM-Visible的Assembly的最佳实践(C#)
- Best Practice in SQL
- Writing a Linux Keylogger in C
- A best practice vs a best system.
- Best practice in PL/SQL
- Best Practice 4 Minimize synchronization in Servlets
- practice in C
- Writing A Threadpool in Rus
- Writing A Threadpool in Rus
- Writing a tf broadcaster (C++)
- Writing a tf listener (C++)
- How to Determine if a file is a .Net assembly (in Delphi and C#)
- Build and Deploy a .NET COM Assembly
- [C0.0] C in Practice
- Writing a DLL (used in Symbian OS)
- Writing a Real Driver -- In User Space
- ok6410学习笔记(13.总线设备驱动)
- 数字图像处理标准图像Lena的故事
- java中volatile关键字的含义
- Weakref应用
- 移动考勤正在撬开考勤市场的大门
- Best Practice in Writing a COM-Visible Assembly (C#)
- Linux makefile 教程 非常详细,且易懂
- 写给想当程序员的朋友
- 初入css,网上资料转载 1
- 虚拟机 搭建LVS + DR + keepalived 高可用负载均衡
- 解决Eclipse内存不足,浅析JVM(转)
- C++ STL
- 苦难有什么价值?
- 计算机专业毕业后大致的工作方向