On Jul 3, 12:20 ¨Âí¬ Áóôï¼âìáãëáðáãèåµ±²­ôéã®®®Àùáèïï®ãïí÷òïôåº
> ----- Original Message ----
> > From: Aston <blackapache512-tic... / yahoo.com>
> > To: Ruby Talk <ruby-t... / ruby-lang.org>; Ruby Core <ruby-c... / ruby-lang.org>
> > Sent: Fri, 2 July, 2010 9:07:00 PM
> > Subject: [ruby-core:30996] Ruby/DL problem
>
> > Hello,
>
> > I have very little experience with dl. But I want to use it to
> > call SetEnvironmentVariable() from Win32. I could use FFI but cannot, since > >this
>
> > script will be supplied to a customer where it is difficult to  ¨Âîóôáìì>
> > SetEnvironmentVariable on
> > MSDNhttp://msdn.microsoft.com/en-us/library/ms686206(v=VS.85).aspx
>
> > reading  ¨Âðáòóå¬ ïìä¬ áîãòùðôéäïãõíåîôáôéïãáíå õð ÷éôè ôèéó óîéððåô¬
> > which  ¨Âãïõòóå äïåó îï÷ïòë
>
> > require 'dl/import'
>
> > module Win32
> > extend  ¨Â̺ºÉíðïòôå> > extern "int SetEnvironmentVariableA( char* lpName, char*  ¨ÂðÖáìõå©¢
> > extern "int GetEnvironmentVariableA( char* lpName, char* lpValue,  ¨Âîô óéúå©¢
> > end
>
> > buff = Array.new( 256, ).pack("c*")
> > Win32.GetEnvironmentVariableA( "ENV_VAR", buff, 255)
> > puts  ¨Âõææ®õîðáã먢᪢©
>
> > this is the error i  ¨Âåô
> > D:/ruby/usr/lib/ruby/1.9.1/dl/importrb:194:in `import_function':  ¨Âîäåæéîåä
> > method `sym' for nil:NilClass (NoMethodError)
> >  ¨Âòïĺ¯òõâù¯õóò¯ìéâ¯òõâù¯±®¹®±¯äì¯éíðïòô®ò⺱±¸ºéî  ¨Âåøôåòî> > from test.rb:5:in  ¨Â¼íïäõìåº×éî³²¾> > from test.rb:3:in  ¨Â¼íáéî¾>
> > machine is WinXP
> > ruby 1.9.1 (2008-10-28 revision 19983)  ¨Â鳸¶­íó÷é߸°Ý
>
> > can anybody suggest a better signature 
>
> > Aston
>
> hmm, nobody here using Ruby.DL ?

Is not DL the problem, but the version you're using. revision 19983 is
*way* older than latest released one:

Pathlevel 378 was revision 26273

Lurking in the NEWS and ChangeLog pointed several changes in DL.

Trying your example with latest RubyInstaller 1.9.1 release:

C:\Users\Luis\Desktop>ruby -v t.rb
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]
C:/Users/Luis/Tools/Ruby/ruby-1.9.1-p378-i386-mingw32/lib/ruby/1.9.1/
dl/import.rb:116: warning: instance variable @type_alias not
initialized
C:/Users/Luis/Tools/Ruby/ruby-1.9.1-p378-i386-mingw32/lib/ruby/1.9.1/
dl/import.rb:194: warning: instance variable @handler not initialized
C:/Users/Luis/Tools/Ruby/ruby-1.9.1-p378-i386-mingw32/lib/ruby/1.9.1/
dl/import.rb:194:in `import_function': undefined method `sym' for
nil:NilClass (NoMethodError)
        from C:/Users/Luis/Tools/Ruby/ruby-1.9.1-p378-i386-mingw32/lib/
ruby/1.9.1/dl/import.rb:118:in `extern'
        from t.rb:5:in `<module:Win32>'
        from t.rb:3:in `<main>'

Which brings the question, why bother on doing this way when Ruby does
it out of the box?

--
Luis Lavena