# How to read pointer data with Win32::API

**URL:** <https://www.ruby-forum.com/t/how-to-read-pointer-data-with-win32-api/188674>\
**Category:** Ruby\
**Created:** [May 16, 2010, 3:09am UTC](https://www.ruby-forum.com/t/how-to-read-pointer-data-with-win32-api/188674 "2010-05-16T03:09:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [May 16, 2010, 3:09am UTC](https://www.ruby-forum.com/t/how-to-read-pointer-data-with-win32-api/188674/1 "2010-05-16T03:09:42Z")

</div>

I have a case where I’m using Win32::API like this:

GMEM\_FIXED = 0  
a = GlobalAlloc(GMEM\_FIXED, x) # x is some large number  
b = GlobalLock(a)  
…  
GetDIBits(\_, \_, \_, \_, b, \_, \_) # \_ are just some variables, which are  
not necessary to show in here  
…

And, since i’m using windows-pr, then the functions above are declared  
like this:  
API.new(‘GlobalAlloc’, ‘LL’, ‘L’)  
API.new(‘GlobalLock’, ‘L’, ‘L’)  
API.new(‘GetDIBits’, ‘LLIIPPI’, ‘I’, ‘gdi32’)

In short, i don’t seem to understand, how can i read the binary data  
lurking behind the pointer of ‘b’, which is actually just a Fixnum  
(because GlobalAlloc and GlobalLock return long). Is it even possible in  
Ruby? Should i try some other approach instead?

Jarmo

---

<div class="post-metadata">

**Author:** ![juuser](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/5f8ce5/32.png) [@juuser](https://www.ruby-forum.com/u/juuser)\
**Post date:** [May 17, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/how-to-read-pointer-data-with-win32-api/188674/2 "2010-05-17T16:56:15Z")

</div>

> In short, i don’t seem to understand, how can i read the binary data  
> lurking behind the pointer of ‘b’, which is actually just a Fixnum  
> (because GlobalAlloc and GlobalLock return long). Is it even possible in  
> Ruby? Should i try some other approach instead?

Suggest FFI since it has things like get\_pointer (though I’m not too  
into it in depth)…  
-rp
