Forums | Admin

Discussion Forums: help

Start New Thread Start New Thread

 

By: Jarmo Pertman
RE: pointers and whatnot in Win32::API [ reply ]  
2010-05-15 19:56
i'll add some more information in here.

GMEM_FIXED = 0
z = GlobalAlloc(0, x) # x is some large number
d = GlobalLock(z)

...

GetDIBits(_, _, _, _, d, _, _) # _ are just some variables, which are not necessary to show in here

...

# b and c will get declared with Array#pack, so they are just some binary data

# and now this line from the previous post comes with slight modifications due to previous lines and understanding of how DL::PtrData#to_s actually works - i'm using #inspect in here to get also "\\000"-s from the binary:
a = b.inspect + c.inspect # + d

So, as far as I understand then I have to get somehow binary data from memory, which is behind pointer d, right? How can i do it? And if i can, then would this line be correct?
a = b.inspect + c.inspect + d.inspect

Jarmo

By: Jarmo Pertman
pointers and whatnot in Win32::API [ reply ]  
2010-05-15 18:50
Hello.

I'm trying to convert one Ruby library, which uses Ruby::DL to use Win32::API and i'm in trouble.

I have to use GlobalAlloc and GlobalLock.

Currently they are declared like this in this library:
extern "void* GlobalAlloc(long, long)"
extern "void* GlobalLock(void*)"

And in windows-pr they are like this:
API.new('GlobalAlloc', 'LL', 'L')
API.new('GlobalLock', 'L', 'L')

So, they are returning long instead of pointer.

And now i got a problem when trying to convert this line:
a = b.to_s(10) + c.to_s(26) + d.to_s(22)

where b, c and d are all DL::PtrData

Since b and c were done with Array#pack#to_ptr, then i just removed #to_ptr and converted them like this:
a = b[0..9] + c[0..25]

But the problem is with d, because it is a Fixnum. How could i solve this problem? Should i handle this situation somehow differently and make GlobalLock and GlobalAlloc to return pointers instead?

Jarmo