VB连接到COM对象 [英] VB connect to COM object

查看:347
本文介绍了VB连接到COM对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白COM对象,或者这是所有的困惑。
我经常用'create','dispatch'COM对象 - 在Python中,在VB中( Obj = win32com.client.Dispatch('Visum.Visum') Obj = CreateObject(Excel.Application))。
这很容易,显而易见,一切都很好。
但是我如何:
a)连接到已经运行的COM对象
b)获取正在运行的进程列表,它们是COM对象

Either I don't understand COM objects, either it's all that confusing. I frequently 'create' , 'dispatch' COM objects - either in Python, either in VB ( Obj = win32com.client.Dispatch('Visum.Visum') or Obj = CreateObject("Excel.Application") respectively). That's easy, obvious and everything's fine. But how can I: a) connect to COM object which is already running b) get list of running processes which are COM objects

  • in VB what is the reference, and additional info on: CreateObject command. In Python it's part of well defined, comprehensive library of win32com whereas in VB it's just single method without reference: http://msdn.microsoft.com/en-us/library/7t9k08y5(v=vs.80).aspx

高度混淆(COM对象,服务器连接,调度,注册)

Highly confusing (COM object,server? connection, dispatching, registering??)

感谢claryfying
Rafal
i2

Thanks for claryfying Rafal i2

推荐答案

首先,会建议阅读一个良好的介绍COM。就个人而言,我认为Don Box的基本COM是关于COM的最好的书。花费几个小时的时间将会节省你很多小时后。

First of all, I would suggest reading a good introduction to COM. Personally, i think that 'Essential COM' by Don Box is the best book about COM. Spending a few hours with it will save you many hours later.

这就是说,让我们来回答你的问题。

That being said, let's move to your questions.

a)要从VB检索现有的COM对象,您需要调用 GetObject 函数。这将只适用于注册了运行对象表。 Excel这样做,所以不应该有任何问题。

a) In order to retrieve an existing COM object from VB, you need to call GetObject function. This will only work for COM objects which are registered with Running Object Table. Excel does this, so there shouldn't be any problems with that.

b)Hans Passant正确地注意到,这个问题没有意义。进程和COM对象是完全不相关的东西,除了进程托管COM对象的事实。它类似于询问哪些进程是类X的实例。但是,进程可以托管COM对象(或其中许多)。这些对象只能临时活着,所以你期望什么?此外,许多COM类都在dll中实现,但是创建的实例显然是在一个进程内托管的 - 所以你会期望什么?

b) as Hans Passant correctly noted, this question doesn't make sense. Processes and COM objects are completely unrelated things, except for the fact that processes host the COM objects. It is similar to asking 'which processes are instances of class X'. However, a process can host a COM object (or many of them). These object can be alive only temporarily, so what would you expect there? Besides, many COM classes are implemented within dlls, but created instances obviously are hosted within a process - so what would you expect there?

这篇关于VB连接到COM对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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