code_junkie

Can Ruby import a .NET dll?

Nov 12th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. namespace ComLib
  5. {
  6. public class LogWriter
  7. {
  8. public void WriteLine( string line )
  9. {
  10. using( var log = new StreamWriter( File.OpenWrite( @"c:log.file" ) ) )
  11. {
  12. log.WriteLine( line );
  13. }
  14. }
  15. }
  16. }
  17.  
  18. [assembly: ComVisible( false )]
  19.  
  20. [ComVisible( true )]
  21. public class LogWriter ....
  22.  
  23. require 'win32ole'
  24.  
  25. lib = WIN32OLE.new('ComLib.LogWriter')
  26. lib.WriteLine('calling .net from ruby via COM, hooray!')
  27.  
  28. "Your Ruby Code" -> RubyCOM -> "COM-Callable Wrappers" -> "Your .NET objects"
  29.  
  30. extern "C" __declspec ( dllexport ) void CallManagedMethod() {
  31. Something^ myManagedObject ...
  32. }
Add Comment
Please, Sign In to add comment