[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[Win32API] Need help with PathCreateFromUrl

djberg96

5/28/2005 7:40:00 PM

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

3 Answers

vanekl

5/28/2005 9:10:00 PM

0

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

djberg96

5/29/2005 3:48:00 AM

0

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

nobu.nokada

5/29/2005 4:35:00 AM

0

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