ruby WIN32OLE c#dll自定义事件监听

时间:2013-02-18 10:01:47

标签: c# ruby events win32ole

我找到了一个关于从Ruby连接到c#dll的好教程: Can Ruby import a .NET dll? 这适用于Ruby => C#,但不适用于c#=> Ruby。 现在我正在考虑使用Ruby可以连接的一些自定义事件。 我在此页面中按照示例A:http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx创建自定义事件。

现在问题是,如何从ruby链接此事件? 在excel我会做:

xl_workbook_events = WIN32OLE_EVENT.new(xl_book, 'WorkbookEvents')
xl_workbook_events.on_event('SheetSelectionChange') do
    # do something when the selection has changed.
end#do

但是,对于自定义c#事件,我不知道.. 的问候,

1 个答案:

答案 0 :(得分:0)

好的,那么,要在C#中创建一个com可访问的DLL:http://www.codeproject.com/Articles/23355/Callback-Functions-and-NET-C-COM-Components

绑定来自ruby的事件:

require 'win32ole’
ole_connection = WIN32OLE.new(“YourNameSpace.YourClassName”)
event = WIN32OLE_EVENT.new(ole_connection)
event.on_event(‘NameOfYourEvent’) do |args| # NameOfYourEvent should be specified in 'CallBackEventInterface' from the example, like: 'TheEvent'. when using that event, arg should containt 'string msg'
    # do some work
    puts args.to_s
end#do
相关问题