[Win32API] Need help with PathCreateFromUrl

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 =
   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

This works for me:

require "Win32API"

MAX_PATH = 255
PathCreateFromUrl =
   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

vanek@acd.net wrote:

This works for me:

require "Win32API"

MAX_PATH = 255
PathCreateFromUrl =
   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

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