[Win32utils-devel] strcpy declaration

Heesob Park phasis at gmail.com
Thu Aug 25 09:28:10 EDT 2011


Hi,

2011/8/25 Daniel Berger <djberg96 at gmail.com>

> In windows-pr strcpy is declared with a prototype of "PL". However, I can't
> make that work:
>
> require 'win32/api'
> include Win32
>
> Strcpy_p = Win32::API.new('strcpy', 'PP', 'L', 'msvcrt')
> Strcpy_l = Win32::API.new('strcpy', 'PL', 'L', 'msvcrt')
>
> buf = 0.chr * 4
> str = "hello"
>
> Strcpy_p.call(buf, str) # works
> p buf
>
> buf = 0.chr * 4
> str = "hello"
>
> Strcpy_l.call(buf, str.unpack('L').first) # fails, segfault
> p buf
>
> I would think either declaration would work but apparently not.
>
> Have we simply not been using this function all this time?
>
>
>
This works:

buf = 0.chr * 5
str = "hello"
Strcpy_l.call(buf, [str].pack('p').unpack('L').first)
p buf


Regards,

Park Heesob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/win32utils-devel/attachments/20110825/5e334b54/attachment.html>


More information about the win32utils-devel mailing list