Had not Dllimport in D?
xky via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 6 06:12:35 PST 2016
First, I really sorry my bad english.
I just want to using Ruby dll file(msvcrt-ruby220.dll).
In the case of C#,
================================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using INT = System.Int32;
namespace RubyTest01
{
static class Ruby
{
public const string RubyDll = "msvcrt-ruby18";
[DllImport(RubyDll)]
public static extern void ruby_init();
[DllImport(RubyDll)]
public static extern INT rb_eval_string_protect(byte[]
script, ref INT state);
public static INT rb_eval_string_protect(string script, ref
INT state)
{
return
rb_eval_string_protect(Encoding.UTF8.GetBytes(script + '\0'), ref
state);
}
}
class Program
{
static void Main(string[] args)
{
INT state = 0;
Ruby.ruby_init();
Ruby.rb_eval_string_protect("open('test.txt', 'w') {| fp|
fp.write(\"Hello World!\\n\")}", ref state);
}
}
================================================================================
I guess D had something like it, but i don't know how to do it.
Thx!
More information about the Digitalmars-d-learn
mailing list