Jos Backus wrote:
> I'm trying to programmatically determine any network opened files on a Windows
> 2003 Server system using the NETAPI32.NetFileEnum API.
>

>     LPBYTE* bufptr,
>     rbuf = "\0" * 10240 # testing, should be *entriesread * sizeof(FILE_INFO_3)

>     memcpy = Win32API.new('msvcrt','memcpy','PPL','P')
>     memcpy.call(rbuf,bufptr,rbuf.size)

> [...] believe I'm either using the wrong parameter template or misinterpreting rbuf.
>
> What could I be doing wrong?
>

Hi Jos,

I just learnt from this so I'll go for the longer answer that you can check.

memcpy in msvcrt.dll takes POINTER to dest, POINTER to src and LONG length
which leads to the template you gave:

>     memcpy = Win32API.new('msvcrt','memcpy','PPL','P')

However bufptr (from NetFileEnum) is a POINTER_to_address (POINTER_POINTER),
so Win32API is *not* required to convert this parameter into a POINTER.
Passed as a L(ONG), it fulfils the requirement that it's a POINTER already.

What this often leads to is multiple definitions such as:

    Pmemcpy1 = Win32API.new('msvcrt', 'memcpy', 'PLL'], 'L')
    Pmemcpy2 = Win32API.new('msvcrt', 'memcpy', 'LPL'], 'L')

for use in cases such as yours.

Call with:

    Pmemcpy1.call(dest ruby string,     src POINTER_POINTER, length)
    Pmemcpy2.call(dest POINTER_POINTER, src ruby string,     length)


Hope that's OK.  Haven't tried ... (I'm not NT)


daz