Another Ruby/DL question

A

awertyui

I'm trying to set a wndProc to a block of ruby code because the
wndProc is getting the messages I have to respond to. I have already
created the window and have the message loop going the only problem is
I would like to be able to pass a block of code instead of passing it a
module function.


This code works.

module MyWin32
extend DL::Importable
dlload 'user32.dll' , 'kernel32.dll'
..
..
..
def my_proc(hwnd,uMsg,wParam,lParam)
puts "My proc CALLED MSG = " + uMsg.to_s
defWindowProc(hwnd,uMsg,wParam,lParam)
end

MY_PROC = callback 'UINT my_proc(HWND,UINT,WPARAM,LPARAM)'

end

@wndclass.lpfnWndProc = MyWin32::MY_PROC.to_ptr

This last line is inside the window class and it works but I would
rather be able to pass it a block of code which can call functions
inside the class instead of the function from the module.


I tried this

doIT = lambda {|hWnd,uInt,wParam,lParam|
class_proc(hWnd,uInt,wParam,lParam)
}
@theCallback = DL.callback('IIIII',doIT)

@wndclass.lpfnWndProc = @theCallback

but this doesn't work. I tried adding .to_ptr to the end but
everything I do gives me errors.

This is one of the errors I keep getting
(eval):16:in `[]=': type mismatch (DL::DLTypeError)
from (eval):16:in `lpfnWndProc='

If anyone knows a better way to send Windows messages between ruby and
c programs let me know.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,054
Latest member
LucyCarper

Latest Threads

Top