It is currently Fri May 24, 2013 4:13 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Modifying A Gadget from within a DLL
PostPosted: Wed Jun 04, 2003 10:53 am 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:47 pm
Posts: 600
Location: New Zealand
it just acured to me, that inside the DLL if you address a gadget by it's ID it won't know what your talking about since the gadget list wasn't created in the DLL, is there anyway to get the commands to address the gadgets from within a DLL ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 12:29 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5188
Location: Germany
You can send the Gadget handle (get it with GadgetID(#Gadget)) to the
dll, and then use the API, to do what you want with the gadget.

This is not as easy, as the PB commands, but it should work. If you need
any help on controlling a specific Gadget with the API, just ask.

Timo

_________________
Perl – The only language that looks the same before and after RSA encryption.
-- Keith Bostic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 12:47 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:47 pm
Posts: 600
Location: New Zealand
Thanks for the info, what a shame PB's gadget commands can't take a gadget address rather than an ID, maybe it should be a feature request.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 1:13 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5188
Location: Germany
> Thanks for the info, what a shame PB's gadget commands can't take a
> gadget address rather than an ID, maybe it should be a feature request.

I think this will come, as soon as the Gadget Numbers are made optional.

I've experimented a bit, and found the following little trick, it let's you
still use PB's commands from within the DLL, to access the Gadgets.

First comes the DLL code:
Code:
ProcedureDLL SetGadgetPointer(Pointer.l)
  Shared NewPointer.l
  NewPointer = Pointer
  !EXTRN _PB_Gadget_ObjectsArea
  !MOV dword EAX, [v_NewPointer]
  !MOV dword [_PB_Gadget_ObjectsArea], EAX
EndProcedure

ProcedureDLL Test(Gadget.l)
  SetGadgetText(Gadget, "This is set from the DLL!")
EndProcedure


And here the Main app:
Code:
Procedure UpdateGadgetPointer(Library.l)
  Shared MainPointer.l
  !EXTRN _PB_Gadget_ObjectsArea
  !MOV dword EAX, [_PB_Gadget_ObjectsArea]
  !MOV dword [v_MainPointer], EAX
  CallFunction(Library, "SetGadgetPointer", MainPointer)
EndProcedure

#Lib = 1
#TextGadget = 1

If OpenLibrary(#Lib, "purebasic.dll")

  If OpenWindow(0, 0, 0, 300, 300, #PB_Window_SystemMenu|#PB_Window_Screencentered, "testing...")
    If CreateGadgetList(WindowID())
   
      TextGadget(#TextGadget, 10, 10, 280, 20, "This text is from the main prog!")
   
      UpdateGadgetPointer(#Lib)
      CallFunction(#Lib, "Test", #TextGadget)
     
      Repeat
      Until WaitWindowEvent() = #PB_EventCloseWindow     
     
    EndIf
  EndIf

  CloseLibrary(#Lib)
EndIf

End


Some notes about this:
Do not Create/Free any Gadgets fro inside the DLL, this should not work
correctly (lead to a crash). Instead, create all Gadgets from the main
App, and only modify them from the DLL!

The UpdateGadgetPointer() function must be called after each time you
created/freed Gadgets, as then this pointer may change internally. So
if you create new Gadgets somewhere, make sure, there is a
UpdateGadgetPointer() somewhere before the next call to the DLL.

That's it, happy coding... 8)

Timo

_________________
Perl – The only language that looks the same before and after RSA encryption.
-- Keith Bostic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 2:56 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:47 pm
Posts: 600
Location: New Zealand
Excellent! & thank you. :D

Gotta learn x86 Asmbler sometime :D


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 2:59 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5188
Location: Germany
> Gotta learn x86 Asmbler sometime

Hehe, me too :wink:

I only know a bit from looking at other peoples code.

Timo

_________________
Perl – The only language that looks the same before and after RSA encryption.
-- Keith Bostic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 3:18 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 6561
> what a shame PB's gadget commands can't take a gadget address
> rather than an ID

What's wrong with address=ButtonGadget(...) ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 3:50 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5188
Location: Germany
He's talking about commands like SetGadgetText()

Timo

_________________
Perl – The only language that looks the same before and after RSA encryption.
-- Keith Bostic


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2003 7:27 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:47 pm
Posts: 600
Location: New Zealand
Works great with my treegadget, weldone most impressed, your name has been added to my list of people that I've used functions for, which is a grand total of 1 so far :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye