1. RE: Shared memory

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

new topic     » topic index » view message » categorize

2. RE: Shared memory

Derek Parnell wrote:
> 
> From: "Matt Lewis"
> > 
> > 
> > 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?  
> 
> Because it is. The 'it' being to have two independant win32lib 
> libraries behave as if they were one - sharing the same variables 
> etc... I am not saying that you can't do Windows apps using a main 
> program and DLLs all written in Euphoria. Sure you can do that. But 
> NOT using win32lib in both. The original question wanted to create 
> Buttons using the DLL from a main window created in the main 
> program's win32lib. 

I guess we parsed the question differently.  I think the real point of 
his question was about integrating a dll with a win32lib app.  Of 
course, it isn't possible to have two copies of win32lib work together 
(although I suppose you could do some really ugly hacks using 
subClassControl).


> In the main program we would have something like ...
>    Win = create(Window, "title", 0, 0, 0, 400,300,0)
> 
> Now this give 'Win' the value 3, but sets up a whole mess of hidden 
> variables inside the win32lib.ew which is inside the main program. 
> 
> If we now do this in the DLL (by passing the value of 'Win')
> 
>    Btn = create(Button, "btn", Win, 5, 5, 20, 40, 0)
> 
> The value of Win (3) is not set up in the DLL's win32lib so it will 
> fail as a parent control. The button will not be created!
> 
> > 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.  
> 
> Ahh...but which win32lib? The main program's copy or the DLL's copy?

Sorry, wasn't clear enough.  There would only be one win32lib: in the 
program.  You could also set it up so that the dll held the copy of 
win32lib, but I think that the idea is probably to add flexible 
modules--truly dynamic 'includes'?--so it really only makes sense to do 
it this way, since then you could have as many dll's as you like plugged 
into the single copy of win32lib.

<snip>

> You seem to be describing a way that a DLL can use the main 
> program's copy of win32lib. And I suspect you will be able to do 
> that, but that was not what was asked for.

Well, it wasn't the method asked for, but I think it's what he really 
wanted.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

3. RE: Shared memory

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 message » categorize

4. RE: Shared memory

Philip D. wrote:

<snip>

> 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.

Yes, I've started coding this up.  I've got wrappers for all global 
functions and procedures for win32lib v0.59.1 for use in a dll, so that 
from the dll's perspective, you can use it almost like you had a local 
copy of win32lib.  The only difference will be that you'll have to get 
the id's of controls created by the main program.  My plan is for the 
main program to call something like:

main_window = create( ... )
publish( "main_window", main_window )

...and then the dll could do something like:

main_window = request( "main_window" )

There will be an include file for your main program, which will do all 
the communication with the dll.  The only thing you'll need to do is to 
tell it which dll to use, and to publish (as above) any required 
information.  I think this should be able to work dynamically, so that, 
for instance, a user could add a component during runtime.

I should have something ready for testing in a couple of days.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

5. RE: Shared memory

Philip D. wrote:
> 
> 
> 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.

I've put it up on the User Contributions (WinDLL).  It's got a simple 
example using Win32Lib v0.59.1.  I don't have a registered version of 
the translator, so you'll have to either compile it yourself or live 
with the delay.

Oh, forgot to put this in the docs:  If you do compile it, you'll 
probably get an error message on line 88 (or so) in main_.c.  Just add a 
semicolon after L0: and it will work.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

6. RE: Shared memory

Matt Lewis wrote:
> 
> 
> Philip D. wrote:
> > 
> > 
> > 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.
> 
> I've put it up on the User Contributions (WinDLL).  It's got a simple 
> example using Win32Lib v0.59.1.  I don't have a registered version of 
> the translator, so you'll have to either compile it yourself or live 
> with the delay.
> 
> Oh, forgot to put this in the docs:  If you do compile it, you'll 
> probably get an error message on line 88 (or so) in main_.c.  Just add a 
> 
> semicolon after L0: and it will work.
> 
> Matt Lewis
> 

Thanks a lot.  I didn't expect it so soon.  You're cool.

Phil

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu