| 件名: | $(lib)/win32/api/WNetConnection ← WNet_connection.rb |
|---|---|
| MLNo. | [ap-ext:0145] |
| 差出人: | たけ(tk)さん take_tk<ggb03124…> |
| 送信日時: | 2003/12/08 16:43 |
| 本文: |
たけ(tk)です
ruby1.8 では Array#pack のテンプレートの書式が変ったんですね。 ---- G:/Apollo/TkUtils/win32/api/WNetConnection.rb ---- # #! ruby -Ks #-- $(lib)/win32/api/ WNetConnection.rb #-- $(lib)/win32/api/ WNetConnection.pi #-- 最終エラーコードのエラーメッセージを返す。 #-- ruby1.8 でArray#pack の書式が変った。P→p。 require( /^1.6/ =~ RUBY_VERSION ? "Win32API" : "dl/win32" ) module Win32 CONNECT_UPDATE_PROFILE = 0x00000001; CONNECT_UPDATE_RECENT = 0x00000002; CONNECT_TEMPORARY = 0x00000004; CONNECT_INTERACTIVE = 0x00000008; ## show dialog if need CONNECT_PROMPT = 0x00000010; CONNECT_NEED_DRIVE = 0x00000020; CONNECT_REFCOUNT = 0x00000040; CONNECT_REDIRECT = 0x00000080; CONNECT_LOCALDRIVE = 0x00000100; CONNECT_CURRENT_MEDIA = 0x00000200; CONNECT_DEFERRED = 0x00000400; CONNECT_RESERVED = 0xFF000000; NetResource = Struct.new(:scope,:type,:display_type,:usage,:local_name,:remote_name,:comment,:provider) class NetResource TEMPLATE = ( /^1.6/ =~ RUBY_VERSION ? "LLLLPPPP" : "LLLLpppp" ) def pack # returns buff [scope,type,display_type,usage,local_name,remote_name,comment,provider].pack(TEMPLATE) end def self.unpack(buff) # returns NetResource object args = buff.unpack(TEMPLATE) self.new( *args ) end end def self.wnet_add_connection3(handle,resource,passwd=nil,user_name=nil,flags=nil) template = ( /^1.6/ =~ RUBY_VERSION ? "LPPPL" : "LpppL" ) @… ||= Win32API.new('mpr','WNetAddConnection3',template,'L') flags ||= CONNECT_INTERACTIVE @…(handle,resource.pack,passwd,user_name,flags) end # -- old API -- # def self.wnet_cancel_connection(name,force=0) # template = ( /^1.6/ =~ RUBY_VERSION ? "PL" : "pL" ) # @… ||= Win32API.new('mpr','WNetCancelConnection','pL','L') # @…(name,flags,force) # end def self.wnet_cancel_connection2(name,flags=0,force=0) template = ( /^1.6/ =~ RUBY_VERSION ? "PLL" : "pLL" ) @… ||= Win32API.new('mpr','WNetCancelConnection2',template,'L') @…(name,flags,force) end end # of module Win32 if __FILE__ == $0 require "win32/util/LastErrorMessage" remote_name = "\\EDiCube-02\hk" ##remote_name = "\\Edicube-02\tk" ##local_name = "k:" local_name = "" user_name = nil passwd = nil ret = Win32.wnet_cancel_connection2(remote_name) if ret != 0 p ret,Win32.last_error_message(ret) else p :ok end res = Win32::NetResource.new(0,0,0,0,local_name,remote_name,"","") ret = Win32.wnet_add_connection3(0,res,passwd,user_name) if ret != 0 p ret,Win32.last_error_message(ret) else p :ok end end ---- Take_tk = KUMAGAI Hidetake たけ(tk)=熊谷秀武 |
|---|---|
| 添付: |
このMLメールは下記のMLメールに対する返信です:
読み込み
中...| <<0144:Re: Shukujitu.rb | 0146:Properties.rb>> |










