Return more than one variable?

Just starting out? Need help? Post your questions and find answers here.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

would an example be like:

Code: Select all


ProcedureDLL properties(MDIGadget)
  *MDI/Width=GadgetWidth(MDIGadget)
  *MDI/Height=GadgetHeight(MDIGadget)
  *MDI/x=GadgetX(MDIGadget)
  *MDI/y=GadgetY(MDIGadget)
EndProcedure

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Thanks, El_Choni.
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

code in library:

Code: Select all

Structure mdiproperties 
  Width.l 
  Height.l 
  x.l
  y.l
EndStructure 

ProcedureDLL defineproperties(MDIGadget,*pointer.mdiproperties)
  *pointer\Width=GadgetWidth(MDIGadget)
  *pointer\Height=GadgetHeight(MDIGadget)
  *pointer\x=GadgetX(MDIGadget)
  *pointer\y=GadgetY(MDIGadget)
EndProcedure 
code in EXE

Code: Select all

If CreateGadgetList(WindowID())
  MDIGadget(#GADGET_MDI, 110, 30, 690, 560, 0, 0 )
  CloseGadgetList()
EndIf


defineproperties(#GADGET_MDI,@????????)

;in event loop to get properties of MDI

         OpenConsole()
          PrintN(Str(MDIprop\Width))
          Input()
          CloseConsole()

this wont work. any ideas of modifications to allow me to get to the structure that is defined in the library. i need to be able to access the original properties of the MDI in order to dock/undock the dockwindow and have the MDI resize as needed +/- the dockwindow width.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
deadmoap
User
User
Posts: 79
Joined: Sun Feb 22, 2004 11:45 pm
Location: Riverdale, Utah
Contact:

Post by deadmoap »

THIS is why pointers were invented.

Code: Select all

ProcedureDLL MyFunc(*var1.LONG,*var2.LONG,*var3.LONG)
   *var1\l=1337
   *var2\l=7777
   *var3\l=666

   ProcedureReturn(1)
EndProcedure
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

deadmoap, i prefer localmotion's approach, to be honest :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

huh?--i have question marks in my code because i dont know what to actually put there. can someone look at my code and show me how to do this. ? the task is to be able to call the defineproperties procedure, and have it return a structure with the MDI gadget width height ect.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post by El_Choni »

AFAIK, if the gadget is created in the exe, you can't use the gadget commands with it from the lib (maybe with #PB_Any?).

I would pass the MDIGadget window handle and use the API with it (GetClientRect_() for dimensions, GetWindowRect_()-->ScreenToClient_()-->ClientToScreen_() for position) to fill the structure.

Regards,
El_Choni
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

ok, thanks for the advice, but without an example i have no idea where to start. i am not even sure about how correct the code i posted is in regards to the pointers and all. the structure created in the LIB is not recognized in the EXE at all.

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

deadmoap wrote:THIS is why pointers were invented.

Code: Select all

ProcedureDLL MyFunc(*var1.LONG,*var2.LONG,*var3.LONG)
   *var1\l=1337
   *var2\l=7777
   *var3\l=666

   ProcedureReturn(1)
EndProcedure
Feeling foolish I will step out and ask, does this also work (gulp) for strings? Better yet, how can I get such to return a/some string(s)?

TIA

(maybe I should just go test :wink:)
Intrigued - Registered PureBasic, lifetime updates user
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

So far, from my lack-of-experience-testing... that this post will be the only one that can do alphanumeric:

viewtopic.php?p=56059#56059

Thanks for that offering :!:
Intrigued - Registered PureBasic, lifetime updates user
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

intrigued, how do you mean? i mean, strings are just blocks of memory, so if a procedure / dll / function has to return a string, you just have to point it to a block of memory where it can dump it's string... i think i must be missing the point...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Intrigued
Enthusiast
Enthusiast
Posts: 501
Joined: Thu Jun 02, 2005 3:55 am
Location: U.S.A.

Post by Intrigued »

blueznl wrote:intrigued, how do you mean? i mean, strings are just blocks of memory, so if a procedure / dll / function has to return a string, you just have to point it to a block of memory where it can dump it's string... i think i must be missing the point...
Nope I'm missing the point. D'oh! :cry:

What I need is for a ProcedureDLL function to return alphanumeric. Going off from what you said can you nudge my tricycle down the sidewalk a bit... via way of an example. I can't seem to get a string version of the LONG version shared early to work.

ProcedureDLL MyFunc(*var1.LONG,*var2.LONG,*var3.STRING)
*var1\l=1337
*var2\l=7777
*var3\s="666"

Debug *var3


ProcedureReturn(1)
EndProcedure


Try to not laugh to hard at my attempt! :wink:
Intrigued - Registered PureBasic, lifetime updates user
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

Still praying? :D

Code: Select all

Structure MEMO
 Text.s
 Length.l
 MemoID.l
EndStructure

Procedure CreateMemo(*lpMemo.MEMO, Text$)
Global UniqueID
*lpMemo\Text = Text$
*lpMemo\Length = Len(Text$)
*lpMemo\MemoID = UniqueID+1
UniqueID+1
ProcedureReturn *lpMemo\MemoID
EndProcedure

CreateMemo(MyMemo.MEMO, "Little-Testing..")
CreateMemo(MyMemo2.MEMO, "2nd MEMO")
CreateMemo(MyMemo3.MEMO, "boring....")

Debug "CreateMemo returned text:"
Debug "MyMemo\Text: "+MyMemo\Text
Debug "MyMemo2\Text: "+MyMemo2\Text
Debug "MyMemo3\Text: "+MyMemo3\Text
Debug "-----"
Debug "CreateMemo returned numbers:"
Debug "MyMemo\Length: "+Str(MyMemo\Length)
Debug "MyMemo2\Length: "+Str(MyMemo2\Length)
Debug "MyMemo3\Length: "+Str(MyMemo3\Length)
Debug "-----"
Debug "MyMemo\MemoID: "+Str(MyMemo\MemoID)
Debug "MyMemo2\MemoID: "+Str(MyMemo2\MemoID)
Debug "MyMemo3\MemoID: "+Str(MyMemo3\MemoID)
That was a quick thing, but it should do what you want, return alphanumeric strings.
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Post by Thorsten1867 »

I use a simple solution:

Code: Select all

Procedure.s test()
  child$ = "Susi"
  age = 9
  ProcedureReturn child$ + "|" + Str(age)
EndProcedure

result$ = test()

child$ = StringField(result$, 1, "|")
Debug child$

age = Val(StringField(result$, 2, "|"))
Debug age
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
josku_x
Addict
Addict
Posts: 997
Joined: Sat Sep 24, 2005 2:08 pm

Post by josku_x »

That's also a good solution, but not for big data, as processing it would be slow.
Post Reply