什么是“注册COM互操作"?真的吗? [英] What does "Register for COM Interop" actually do?

查看:403
本文介绍了什么是“注册COM互操作"?真的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VS项目选项注册COM互操作"实际上到底做什么?因为在启用此选项的情况下构建库时,可以从VBScript在库上调用CreateObject.但是,如果我没有此构建,然后手动运行regasm,则CreateObject将失败.所以我想知道-VS2010是做什么的呢?

What exactly does the VS project option "Register for COM interop" actually do? Because when I build my library with this option enabled I can call CreateObject on my library from VBScript. But if I build without this and then run regasm manually CreateObject fails. So I'm wondering -- what does VS2010 do that I'm not doing?

推荐答案

与使用/tlb和/codebase选项运行Regasm.exe的功能相同./codebase选项可能是您忘记的选项. Regasm喜欢假设您将DLL放入GAC并在不这样做时生成警告. GAC确实是避免DLL Hell(始终是COM问题)的一种非常好的方法.但是不适合在您的开发机器上使用,您不想在开发和测试代码时污染GAC.这仅在用户的计算机上很重要,该计算机很可能会暴露于多个版本.

It does the same thing as running Regasm.exe with the /tlb and /codebase options. The /codebase option is probably the one you forgot. Regasm likes assuming you put the DLL in the GAC and generates a warning when you don't. The GAC is indeed a very good way to avoid DLL Hell, always a COM problem. But not appropriate on your dev machine, you don't want to pollute the GAC while developing and testing the code. It only matters on your user's machine, the one that's likely to be exposed to multiple versions.

在64位计算机上使用错误版本的Regasm.exe是另一种麻烦的方式,您的计算机上通常有4个版本.确保区分32位和64位版本(c:\ windows \ microsoft \ framework与framework64),它们编写不同的注册表项.您想选择一个与客户端应用程序兼容的应用程序.也可以同时使用两者,.NET代码可以在任何一种模式下运行,但是非常不寻常.并区分v2.0.50727(.NET 2.0到3.5SP1)和v4.0版本.选择正确的Visual Studio命令提示符是成功的一半.

Using the wrong version of Regasm.exe on a 64-bit machine is another way to get in trouble, there are usually 4 versions on your machine. Be sure to distinguish the 32-bit and 64-bit versions (c:\windows\microsoft\framework vs framework64), they write different registry keys. You want to pick the one that's compatible with the client app. Using both is okay too, .NET code can run in either mode, but pretty unusual. And distinguish between the v2.0.50727 (.NET 2.0 through 3.5SP1) and the v4.0 versions. Picking the right Visual Studio Command Prompt is half the battle.

这篇关于什么是“注册COM互操作"?真的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆