Win32API question - PathAppend (in/out variable issue)

D

Daniel Berger

Hi all,

Ruby 1.8.2.
Windows XP Pro

I'm having a bit of an issue with an in/out variable with the
PathAppend() function. I have no problem when I use a C extension, but
when I used Win32API, I don't get the desired output. Here's the code:

# test.rb
require "Win32API"

PathAppend = Win32API.new("shlwapi","PathAppend","PP","L")

path = 'C:\foo'
PathAppend.call(path, 'bar')

p path # 'C:\foo', but expect 'C:\foo\bar'

I've tried padding 'path' and a few other tricks, but nothing has
worked. What am I doing wrong?

Regards,

Dan
 
P

Paul Leonard

Daniel -

This works:

require "Win32API"

MAX_PATH =3D 256

inbuf =3D Array.new.fill(0.chr,0..MAX_PATH-1).join

PathAppend =3D Win32API.new("shlwapi","PathAppend","PP","L")

path =3D 'C:\foo'

inbuf[0..path.length-1] =3D path

PathAppend.call(inbuf, 'bar'+ 0.chr)

puts inbuf.strip!

Returns:
C:\foo\bar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,240
Latest member
pashute

Latest Threads

Top