# \[Win32API\] Need help with PathCreateFromUrl

**URL:** <https://rubytalk.org/t/win32api-need-help-with-pathcreatefromurl/18657>\
**Category:** ruby-talk\
**Created:** [28 May 2005 19:40 UTC](https://rubytalk.org/t/win32api-need-help-with-pathcreatefromurl/18657 "2005-05-28T19:40:20Z")\
**Posts on this page:** 4\
**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:** [28 May 2005 19:40 UTC](https://rubytalk.org/t/win32api-need-help-with-pathcreatefromurl/18657/1 "2005-05-28T19:40:20Z")

</div>

Hi all,

Ruby 1.8.2  
Windows XP

The following script dies a horrible death. I've tried different ways  
of padding the url and buffer, but nothing has worked. Do I have the  
method signature wrong?

# test.rb  
require "Win32API"

MAX\_PATH = 255  
PathCreateFromUrl =  
&nbsp;&nbsp;&nbsp;Win32API.new("shlwapi", "PathCreateFromUrl", "PPLL", "L")

buf = 0.chr \* MAX\_PATH  
url = "file:///C:/foo" + 0.chr # I tried other ways of padding this  
len = buf.length

p PathCreateFromUrl.call(url, buf, len, 0) # kaboom!  
p buf

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![Lou\_Vanek](https://avatars.discourse-cdn.com/v4/letter/l/c77e96/32.png) [@Lou\_Vanek](https://rubytalk.org/u/Lou_Vanek)\
**Post date:** [28 May 2005 21:15 UTC](https://rubytalk.org/t/win32api-need-help-with-pathcreatefromurl/18657/2 "2005-05-28T21:15:20Z")

</div>

This works for me:

require "Win32API"

MAX\_PATH = 255  
PathCreateFromUrl =  
&nbsp;&nbsp;&nbsp;Win32API.new("shlwapi", "PathCreateFromUrl", 'PPPL', "i")

buf = 0.chr \* MAX\_PATH

url = "file://localhost/c:/winzip.log"

lpLen = " " \* 4 # lpLen is a pointer to a LONG

p PathCreateFromUrl.call(url, buf, lpLen, 0)  
p buf

#config: Windows XP Pro SP2, ruby 1.8.2, cygwin

---

<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:** [29 May 2005 03:50 UTC](https://rubytalk.org/t/win32api-need-help-with-pathcreatefromurl/18657/3 "2005-05-29T03:50:20Z")

</div>

vanek@acd.net wrote:

> This works for me:
> 
> require "Win32API"
> 
> MAX\_PATH = 255  
> PathCreateFromUrl =  
> &nbsp;&nbsp;&nbsp;Win32API.new("shlwapi", "PathCreateFromUrl", 'PPPL', "i")
> 
> buf = 0.chr \* MAX\_PATH
> 
> url = "file://localhost/c:/winzip.log"
> 
> lpLen = " " \* 4 # lpLen is a pointer to a LONG
> 
> p PathCreateFromUrl.call(url, buf, lpLen, 0)  
> p buf
> 
> #config: Windows XP Pro SP2, ruby 1.8.2, cygwin

That worked great, thanks.

Dan

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [29 May 2005 04:34 UTC](https://rubytalk.org/t/win32api-need-help-with-pathcreatefromurl/18657/4 "2005-05-29T04:34:43Z")

</div>

Hi,

At Sun, 29 May 2005 06:15:20 +0900,  
vanek@acd.net wrote in [ruby-talk:143901]:

> lpLen = " " \* 4 # lpLen is a pointer to a LONG

lpLen = [buf.size].pack("l")

> **···**
>
> > p PathCreateFromUrl.call(url, buf, lpLen, 0)
> 
> --  
> Nobu Nakada
