I imagine I can compile a C# DLL and then expose it as a COM object so that it can be CreateObject'd from VBscript. I'm just not sure the steps involved in doing this...
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Generic Generics in Managed C++
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
You should use the
regasm
utility to register an assembly (just like you doregsvr32
with COM servers). Then you can use it from COM. Make sure it's installed in the GAC. The stuff should have[ComVisible(true)]
to be usable from COM.There's a "COM Accessible" option for each project you can select. Then, of course, you have to register the assembly to use it, but that's about it.
I had to go hunting a bit to find it for C# (I'm used to VB.Net), but you can find the option by double-clicking on the
Properties
folder in the Solution Explorer, choosing theApplication
tab and then clicking theAssembly Information...
button.It can be very simple to do this. But there are a lot of places where it's not so simple. It depends a lot on what your class needs to be able to do, and how you intend to deploy it.
Some issues to consider:
regasm /codebase
.regasm
assign them, but they'll be different every time (and every place) the class is registered. If you need the GUIDs to remain invariant across installations, you'll need to mark members with theGuid
attribute.MarshalAs
attribute.InterfaceType
attribute.There's a very good (if dated) article about COM interop and .Net here. (A lot of things that article talks about, like generating type libraries, is handled for you automatically now.) And Microsoft's documentation is up to date, but not quite so detailed.