# Win32API question - PathAppend (in/out variable issue)

**URL:** <https://rubytalk.org/t/win32api-question-pathappend-in-out-variable-issue/18542>\
**Category:** ruby-talk\
**Created:** [20 May 2005 20:40 UTC](https://rubytalk.org/t/win32api-question-pathappend-in-out-variable-issue/18542 "2005-05-20T20:40:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Berger3](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@Daniel\_Berger3](https://rubytalk.org/u/Daniel_Berger3)\
**Post date:** [20 May 2005 20:40 UTC](https://rubytalk.org/t/win32api-question-pathappend-in-out-variable-issue/18542/1 "2005-05-20T20:40:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul\_Leonard](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@Paul\_Leonard](https://rubytalk.org/u/Paul_Leonard)\
**Post date:** [20 May 2005 23:20 UTC](https://rubytalk.org/t/win32api-question-pathappend-in-out-variable-issue/18542/2 "2005-05-20T23:20:07Z")

</div>

Daniel -

This works:

require "Win32API"

MAX\_PATH = 256

inbuf = Array.new.fill(0.chr,0..MAX\_PATH-1).join

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

path = 'C:\foo'

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

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

puts inbuf.strip!

Returns:  
C:\foo\bar

> **···**
>
> On Sat, 21 May 2005 05:40:15 +0900, Daniel Berger wrote:
> 
> > 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
