From: daz Date: 2004-07-14T04:57:21+09:00 Subject: Re: win32api: how to access NetFileEnum results? Jos Backus wrote: > > On Tue, Jul 13, 2004 at 04:32:23PM +0900, daz wrote: > > Next question is: using Pmemcpy1, how do I initialize the src POINTER_POINTER > argument (i.e. bufptr)? Setting it to 0 causes ruby to segfault (both 1.8.1 > and today's 1.8.2 snapshot installed using the one-click installer) and > setting it to "\0" * 4 causes a TypeError as the template specifies a Long > and I'm supplying a String. > Re-reading the API suggests a change of tack. I think that memcpy isn't required. bufptr needs to be POINTER to return_struct, so: ## rbuf = "\0" * 10240 # return_struct ## bufptr = [rbuf].pack('P') # POINTER to rbuf (as packed string) ## NetFileEnum needs a POINTER to bufptr # Win32API 'P' template will handle that So my (UNTESTED) interpretation is: #---------------------------------- require 'Win32API' MAX_PREFERRED_LENGTH = -1 level = 3 entriesread = "\0" * 4 totalentries = "\0" * 4 resume_handle = "\0" * 4 rbuf = "\0" * 10240 # testing, should be *entriesread * sizeof(FILE_INFO_3) bufptr = [rbuf].pack('P') # POINTER to rbuf (as packed string) NetFileEnum = Win32API.new('netapi32', 'NetFileEnum', 'PPPNPNPPP', 'I') ret = NetFileEnum.call(0,0,0,level,bufptr,MAX_PREFERRED_LENGTH,entriesread,totalentries,resume_handle) if 0 != ret puts "Failed:#{ret}" exit end p rbuf #---------------------------------- Good or bad ? daz