×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

请教一个关于COM 回调函数和Powershell的问题

How to associate the COM event source method to the sink in Powershell?

We have a COM component with an event source method. Once some special events happen during the execution, it will send some information back to the caller( event_sink/callback function).

Suppose the COM component name is "Taskhandler" and the event source method name is "OnStatusupdate". For example, in VBScript, we can simply give the sub-procedure name as "Taskhandler_OnStatusupdate(...)", then once events are fired, that procedure will be called automatically.

Now, we want to do the same thing in the Powershell script - once events are fired, a special function in the caller will be called. Unfortunately, we don't know how to associate the event source with the callback function. Does anyone know how to solve this problem?

谢谢
Report

Replies, comments and Discussions:

  • 工作学习 / 专业技术讨论 / 请教一个关于COM 回调函数和Powershell的问题
    How to associate the COM event source method to the sink in Powershell?

    We have a COM component with an event source method. Once some special events happen during the execution, it will send some information back to the caller( event_sink/callback function).

    Suppose the COM component name is "Taskhandler" and the event source method name is "OnStatusupdate". For example, in VBScript, we can simply give the sub-procedure name as "Taskhandler_OnStatusupdate(...)", then once events are fired, that procedure will be called automatically.

    Now, we want to do the same thing in the Powershell script - once events are fired, a special function in the caller will be called. Unfortunately, we don't know how to associate the event source with the callback function. Does anyone know how to solve this problem?

    谢谢
    • If PowerShell can wrap its function into an IDispatch interface like JavaScript in IE, you can simply pass the function into COM as an IDispatch interface; otherwise your COM component need to support connection ports.
      • 谢谢你的回复。 1. Powershell应该是支持Wrap的;2. 这个COM是实现了IConnectionPoint接口的。 因为我只是初级Powershell使用者,不清楚怎么做, 您能否给给简单的例子说一下怎么Wrap或连接Connection Port with Powershell, 或给个相关连接。 谢谢
        • 我不懂Powershell。我在项目中是将JavsScrip函数当作一个IDispatch通过函数调用直接转递给COM,然后COM以0作为id来调用这个函数,这样的话COM不需要支持出接口。如果你的COM已经有了OLE兼容的出接口,那应该更简单,VS应该能产生框架代码的。
          • 谢谢。我会尝试你的方法。