需要创建 COM DLL 以在“Excel.Application”等脚本中使用

发布于 2024-11-16 01:26:12 字数 1018 浏览 3 评论 0原文

我想使用 VSS 2010 创建 COM DLL 并且需要注册到注册表。我的目标是我想使用创建的 DLL,如“Excel.Application”、“Word.Application”、“Wscript.Shell”之类的。

我想使用 CreateObject / New OleObject 方法创建实例,并在我的脚本(VBScript 或 JavaScript)中使用相同的方法。

谁能帮我创建一个 COM 对象以及如何注册它?

我尝试创建 COM 对象并尝试使用 RegSvr32.exe 进行注册。它说“dll已加载,但未找到入口点。请确保有效的dll或ocx”

这是我的代码供您参考...

<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1 

Public Const ClassId As String = "b3b13b6c-6de5-47cb-ad6f-0ae5c7ce5c59"
Public Const InterfaceId As String = "68536b50-1b47-42d5-970f-d3d34b56d681"
Public Const EventsId As String = "413fa5c3-76fa-44d0-b753-1f3d3f52dbaf" 

' A creatable COM class must have a Public Sub New() with no parameters, 
' otherwise, the class  will not be
' registered in the COM registry and cannot be created
' via CreateObject.

Public Sub New()
    MyBase.New()
End Sub


Public Sub Test1()
    Console.WriteLine("Test1....")
End Sub

End Class

谢谢,
尚穆加维尔

I want to create a COM DLL using VSS 2010 and need to register to Registry. My aim is I want use that created DLL like "Excel.Application", "Word.Application", "Wscript.Shell" kind-of.

I want to create instance using CreateObject / New OleObject methods and use the same in my Scripting (VBScript or JavaScript).

Any one help me to create a COM object and how to register it?

I tried to create COM Object and tried to register using RegSvr32.exe. It says "dll was loaded but no entry point found. Make sure valid dll or ocx"

Here is my code for your ref...

<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1 

Public Const ClassId As String = "b3b13b6c-6de5-47cb-ad6f-0ae5c7ce5c59"
Public Const InterfaceId As String = "68536b50-1b47-42d5-970f-d3d34b56d681"
Public Const EventsId As String = "413fa5c3-76fa-44d0-b753-1f3d3f52dbaf" 

' A creatable COM class must have a Public Sub New() with no parameters, 
' otherwise, the class  will not be
' registered in the COM registry and cannot be created
' via CreateObject.

Public Sub New()
    MyBase.New()
End Sub


Public Sub Test1()
    Console.WriteLine("Test1....")
End Sub

End Class

Thanks,
Shanmugavel.C

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

养猫人 2024-11-23 01:26:12
  1. 创建类库
  2. 在 .vb 文件内,首先创建一个接口。
  3. 通过继承Interface来创建类。
  4. 在属性的“签名”选项卡下创建强名称。
  5. 在属性的“编译”选项卡下启用“注册 Com Interop”
  6. 输入程序集信息。
  7. 构建解决方案。

之后,

  1. 转到“Visual Studio 2010 命令提示符”
  2. 导航到 dll 路径
  3. 使用“regasm”注册 dll,如 regasm test.dll /tlb:test.tlb

现在注册表项将在 CLSID 和接口下完成。然后

  1. 使用“gacutil.exe”(如 gacutil /i test.dll)导出到 GAC(全局程序集缓存,即 C:\Windows\Microsoft.Net\Assembly)。

就这样......我们可以使用 COM 应用程序......

请参阅链接:

http://www.codeproject.com/KB/COM/nettocom.aspx
http://www.15seconds.com/issue/040721.htm

  1. Create a CLass Library
  2. Inside the .vb file, Create a Interface first.
  3. Create class by inheriting from Interface.
  4. Create Strong Name under "Signing" TAB of Properties.
  5. Enable the "Register for Com Interop" under "compile" TAB of Properties
  6. Enter the Assembly Information.
  7. Build the Solution.

After this,

  1. Goto "Visual Studio 2010 Command Prompt"
  2. Navigate to dll path
  3. Register the dll using "regasm" like regasm test.dll /tlb:test.tlb

Now Registry Entries will be done under CLSID and Interface. Then

  1. Export to GAC(Global Assembly Cache ie. C:\Windows\Microsoft.Net\Assembly) using "gacutil.exe" like gacutil /i test.dll

That's all.... We can use the COM application....

Refer the links:

http://www.codeproject.com/KB/COM/nettocom.aspx
http://www.15seconds.com/issue/040721.htm

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文