[Win32API] Need help with PathCreateFromUrl

D

Daniel Berger

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
 
V

vanek

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
 
D

Daniel Berger

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
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top