How to register .NET components with COM

 

Summary Extending the ArcGIS applications with custom .NET components requires that the .NET classes are made available to the component object model (COM) runtime by registering the components in the COM registry. The three ways to perform this task are outlined in this document. In addition, if the component is to be used from a COM development environment, you may also want to export a type library, which is also outlined in this document.

Building the project on a development machine

  • Use: On a development machine
 
When you want to register an assembly for COM interop on a development machine, the simplest way is to open the project in Visual Studio 2005, ensure the project-level Register for COM Interop property is set to true, then build the project.
 
To check a project's settings, click Project Properties from the Project menu, select the Build (C#) or Compile (VB.NET) page, and select the Register for COM Interop check box.
 

Registering by command, using the Regasm utility

  • Use: When testing on a different machine and you do not have an installation program
 
Sometimes you may want to register an assembly for COM interop without building the project; for example, when first testing your component or if you do not have access to the assemblies source code.
 
In this case, you can use the assembly registration utility Regasm that ships with the .NET Framework Software Development Kit (SDK) or Visual Studio 2005. Regasm will add entries to the registry, which allows a COM (unmanaged) application to consume .NET classes via COM interop.
 
Machines with either Visual Studio 2005 or the freely available .NET Framework SDK will have this utility installed and other machines may not; therefore. this is not a viable solution for general deployment of your components.
 
Using the Regasm command line utility
To use the Regasm command line utility:
  • If the target machine has Visual Studio installed, open the Visual Studio 2005 command prompt (the ordinary command prompt will not have the appropriate environment variables set to use this tool).
  • If the target machine does not have Visual Studio installed but does have the .NET Framework SDK installed, use the SDK command prompt by choosing Programs, then Microsoft .NET Framework SDK v2.0. If you cannot find it, open a command prompt at the path where Regasm is located. For example, the .NET Framework 2.0 default installation path is C:/Windows/Microsoft.NET/Framework/v2.0.50727.
 
The following example shows the command used to register the assembly called EditTools with COM. The full path to the assembly should be given unless the current directory of the command prompt is the directory where the assembly is located:
 
regasm EditTools.dll /codebase
 
The /codebase parameter is an optional parameter that adds information to the registry specifying the path on disk of the assembly. If the component is not to be deployed to the global assembly cache (GAC), then this option will be required for ArcGIS to find your component successfully; if the component is installed to the GAC, the option is not required. Regasm has many other options; for a full list, type regasm /? or refer to Microsoft Developer Network (MSDN).
 
Regasm can also be used to unregister assemblies from COM interop, as shown in the following example:
 
regasm EditTools.dll /unregister 
 

Using an installation program

  • Use: When deploying to your user
 
Finally, you can create an installation program, which will deploy your component and add to the installation program an automatic registration step that will register your component for COM interop.
 
You can create installation programs by using either third-party installation software or using a Visual Studio Setup Project. For an example of how to create a setup project for a component using WISE, see How to deploy an application.
 

Type libraries for managed components


A type library (.tlb) can also be exported that contains information describing the types in the assembly. You may want to generate a type library for a component if that component will be used from another development environment, such as within the Visual Basic for Applications (VBA) environment embedded with the ArcGIS applications. If you want to add custom commands and tools using the Customize dialog box within the ArcGIS applications, you need to generate a type library.
 
Visual Studio will generate this .tlb automatically if you have checked the Register for COM Interop setting. If you do not have a .tlb for an existing component, one can be generated by using the Regasm utility and the /tlb option. See the following:
 
regasm EditTools.dll /tlb:EditTools.tlb
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值