# Help using ruby/dl to pass LPDWORD

**URL:** <https://www.ruby-forum.com/t/help-using-ruby-dl-to-pass-lpdword/123412>\
**Category:** Ruby\
**Created:** [December 17, 2007, 2:03pm UTC](https://www.ruby-forum.com/t/help-using-ruby-dl-to-pass-lpdword/123412 "2007-12-17T14:03:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mshah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ee7513/32.png) [@mshah](https://www.ruby-forum.com/u/mshah)\
**Post date:** [December 17, 2007, 2:03pm UTC](https://www.ruby-forum.com/t/help-using-ruby-dl-to-pass-lpdword/123412/1 "2007-12-17T14:03:37Z")

</div>

Hi All,  
I want to get the process ID by supplying the window handle to  
the following API.

DWORD GetWindowThreadProcessId(HWND hWnd,LPDWORD lpdwProcessId);

However I am failing to understand how can I pass the Pointer to  
DWORD to DL call object.

I tried passing PtrData object, but it does not seem to be returning  
the PID value as I had expected. Following is my irb session:

# =========================================== irb(main):001:0\> require ‘dl’ =\> true irb(main):002:0\> rpid = 0 =\> 0 irb(main):004:0\> ptr = DL::PtrData.new(rpid) =\> #\<DL::PtrData:0x2a05ce8 ptr=0x0 size=0 free=0x0\> irb(main):005:0\> user32=DL.dlopen(“user32”) =\> #DL::Handle:0x2de7a90 irb(main):006:0\> getpid = user32[‘GetWindowThreadProcessId’, ‘LLP’] =\> #\<DL::Symbol:0x2a0d070 func=0x77d48a58 ‘long GetWindowThreadProcessId(long, void \*);’\> irb(main):007:0\> getpid.call(0x00120464, ptr) =\> [4032, [1180772, #\<DL::PtrData:0x2a05ce8 ptr=0x0 size=0 free=0x0\>]] irb(main):008:0\> p ptr #\<DL::PtrData:0x2a05ce8 ptr=0x0 size=0 free=0x0\> =\> nil

I was expecting to ptr data to change to the pid of my process, however  
it has not changed at all.

Am I missing something obvious. Is there any other way I can do this.

Thanks and Regards,  
Manish
