RE: Shared memory

new topic     » goto parent     » topic index » view thread      » older message » newer message

Matt Lewis wrote:
> 
> 
> Derek Parnell wrote:
> > 
> > From: "Philip D." <philip1987 at hotmail.com>
> > 
> > > I really would like to do this because I want to make a program 
> > > with the win32lib and have DLLs which can put controls on the 
> > > window made with the program.  This currently can't be done 
> > > because the DLL has to include a whole fresh set of win32lib 
> > > variables.  (see topic: Referencing Control Ids in DLLs)  If I 
> > > could share their memory, the DLL would know about the window 
> > > created in the program.
> > 
> > Stop! Read my lips! You can't do this with win32lib. It is NOT 
> > built for this. 
> > 
> > You can either place win32lib in your main program OR put it in the 
> > DLL, but you can't do both and have it work how you want to.
> 
> Why does everyone say this is impossible?  The key is to set up some 
> callback mechanism in your program for the dll to call the correct 
> win32lib routines.  You'd need to figure out which routines you wanted 
> to call from win32lib.  You'd also want to know ahead of time which 
> control id's you'd want to share.  Then set up id's as constant values:
> 
> constant
> MAIN_WIN = 1,
> EDIT_TEXT = 2,
> THE_COMBO = 3, -- etc...
> 
> CREATE = 1,
> SET_FOCUS = 2,
> SET_TEXT = 3 -- etc...
> 
> In your app, then set up a sequence to hold the values and routine ids:
> 
> sequence my_controls, win_routines
> my_controls = { main_win, edit_text, the_combo }
> win_routines = { routine_id("create"), routine_id("setFocus"),
>  routine_id("setText")}
> 
> ...and a couple of callbacks:
> 
> function get_control_id( atom id )
> 	return my_controls[id]
> end function
> constant 
> GET_OBJECT = define_c_func( my_dll, "get_object",{},E_OBJECT),
> SET_OBJECT = define_c_proc( my_dll, "set_object", {E_OBJECT})
> function call_win_func( atom routine )
> 	sequence args
> 	object return_val
> 	args = c_func( GET_OBJECT, {})
> 	return_val = call_func( win_routines[routine], args )
> 	if atom(return_val) then
> 		return return_val
> 	end if
> 	c_proc( SET_OBJECT, { return_val })
> 	return -1
> end function
> 
> Unfortunately, only in calls *to* the dll will you be able to pass 
> sequences, which is why you'll have to have functions in the DLL called 
> get_object() and set_object() that can return and set the value of a 
> local variable.  It's  somewhat complicated, but I don't see why it 
> couldn't work.  I may try to code this up as a standalone library...
> 
> Matt Lewis
> 

This is a little confusing; if you have time, could you give a demo of 
how to make a main window with a button in it ( button created in DLL).  
I was speaking for just a way to do this, not necessarily a way to do it 
with two win32lib includes.

Thanks,
Phil

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu