[solved] GetGadgetItemText .... C/C++ returned string

Just starting out? Need help? Post your questions and find answers here.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

[solved] GetGadgetItemText .... C/C++ returned string

Post by eddy »

How to return string without ProcedureReturn ?
Last edited by eddy on Thu Dec 18, 2008 7:47 pm, edited 2 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Post by IceSoft »

Here a quick and dirty example:

Code: Select all

Global  s.s = "Anton"
Procedure tt()
  Debug s
  s = "Berta"
EndProcedure
tt()
Debug s
End
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Demivec
Addict
Addict
Posts: 4267
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Post by Demivec »

Here's mine:

Code: Select all

Procedure sample(*a.String)
  *a\S = "abcdef"
EndProcedure

Define a.String
sample(@a)
Debug a\S
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Um... use a GLOBAL variable to hold the $ ??? Then you could change it in multiple procedures and viola!

:D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

My problem is related to imported functions from C/C++ lib
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

Yipes... well so much for the KISS programming method! :D

Actually if they had it named as global... i "think" you could access it if you knew the variable name...

Does anyone know if this is true or are the little people in my head telling me lies again! :wink:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Rook Zimbabwe wrote:Um... use a GLOBAL variable to hold the $ ??? Then you could change it in multiple procedures and viola!
Using just

Code: Select all

Shared s.s
at the beginning of IceSoft's procedure instead of making the string Global would eliminate that problem... :wink:
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Post by traumatic »

Rook Zimbabwe wrote:Then you could change it in multiple procedures and viola!
Puntastic! Love it. :D
Good programmers don't comment their code. It was hard to write, should be hard to read.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

This is a short example to understand this problem:
Where is the string result ?

Code: Select all

CompilerIf Defined(GADGET_VT, #PB_Structure)=#False
   Structure GADGET_VT  ; PB_GadgetVT
      GadgetType.i      ; gadget type (used by GadgetType command)
      SizeOf.i          ; Size of structure
      
      *GadgetCallback
      *FreeGadget
      *GetGadgetState
      *SetGadgetState
      *GetGadgetText
      *SetGadgetText
      *AddGadgetItem2
      *AddGadgetItem3
      *RemoveGadgetItem
      *ClearGadgetItemList
      *ResizeGadget
      *CountGadgetItems
      *GetGadgetItemState
      *SetGadgetItemState
      *GetGadgetItemText
      *SetGadgetItemText
      *OpenGadgetList2
      *GadgetX
      *GadgetY
      *GadgetWidth
      *GadgetHeight
      *HideGadget
      *AddGadgetColumn
      *RemoveGadgetColumn
      *GetGadgetAttribute
      *SetGadgetAttribute
      *GetGadgetItemAttribute2
      *SetGadgetItemAttribute2
      *SetGadgetColor
      *GetGadgetColor
      *SetGadgetItemColor2
      *GetGadgetItemColor2
      *SetGadgetItemData
      *GetGadgetItemData
   EndStructure
CompilerEndIf
CompilerIf Defined(GADGET, #PB_Structure)=#False
   Structure GADGET     ; PB_Gadget
      hwnd.i            ; gadget window handle
      *VT.GADGET_VT     ; gadget commands
      *GadgetData       ; gadget data           (used by SetGadgetData command)
      *OldCallback      ; window CALLBACK       (used by purebasic CALLBACK)
      Dates.i[4]        ; .....
   EndStructure
CompilerEndIf

If OpenWindow(0, 0, 0, 222, 200, "test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   ListIconGadget(10, 10, 10, 200, 220, "header", 100)
   AddGadgetColumn(10, 1, "header2", 100)
   AddGadgetItem(10, 0, "items..."+#LF$+"item")
   
   *g.GADGET=IsGadget(10)
   Debug GetGadgetItemText(10,0,0) ; <--- string result
   Debug Len(GetGadgetItemText(10, 0, 0)) ; <--- 8
   Debug CallFunctionFast(*g\VT\GetGadgetItemText, *g, 0, 0, *res) ; <--- 8 not a string pointer 
   Debug *res    ; <--- 0 no string pointer

   
   Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Last edited by eddy on Tue Dec 16, 2008 4:10 pm, edited 2 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

pseudo

Code: Select all

void PB_Test(int pos)
{
    char* out;
	char* temp = "lala"
	
	out = SYS_GetOutputBuffer(strlen(temp),pos);
	
	CopyMemory(temp,out);
	
	out += len;
	*out = 0;	
}
pb desc

Code: Select all

Test,() - 
String | Unicode | DebuggerCheck
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Did you test my code (above) ?
Did you know how to get the string result ?
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

The string is in _PB_StringBase. What will you plan?
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

I plan to customize a PB gadget.
Like that :

Code: Select all

*gadget\VT\GetGadgetItemText=@Custom_GetGadgetItemText()
*gadget\VT\GetGadgetItemState=@Custom_GetGadgetItemState()

Code: Select all

Procedure.s Custom_GetGadgetItemText(*gadget.GADGET, Position, Column) ; <--- error
   ;
   ; custom code here ....
   ;
   Protected result$
   result$=PeekS(CallFunctionFast(*gadget\VT\GetGadgetItemText, *gadget, Position, Column))  ; <--- error
   ProcedureReturn result$  ; <--- error
      
EndProcedure  ; <--- error
There's no problem to get the custom gadget state
but I don't understand how to get the custom gadget text.

I want to code this function to improve the ReBarGadet and ListIconPlus ( trick'n tips forum)

Image
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

solution : Add extra parameter + using procedureDLL

Code: Select all


Structure GADVT
   GadgetType.i
   SizeOf.i
   
   *GadgetCallback
   *FreeGadget
   *GetGadgetState
   *SetGadgetState
   *GetGadgetText
   *SetGadgetText
   *AddGadgetItem2
   *AddGadgetItem3
   *RemoveGadgetItem
   *ClearGadgetItemList
   *ResizeGadget
   *CountGadgetItems
   *GetGadgetItemState
   *SetGadgetItemState
   *GetGadgetItemText
EndStructure
Structure GAD
   hwnd.i
   *VT.GADVT
EndStructure

OpenWindow(0, 0, 0, 222, 200, "test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(10, 10, 10, 200, 220, "header0", 100)
AddGadgetColumn(10, 1, "header1", 100)
AddGadgetItem(10, 0, "item0"+#LF$+"item1")
AddGadgetItem(10, 1, "item0"+#LF$+"item1")
AddGadgetItem(10, 2, "item0"+#LF$+"item1")

*g.GAD=IsGadget(10)

Prototype.s GetGadgetItemText_1(*g.GAD, pos, col)
Global GetGadgetItemText_1.GetGadgetItemText_1=*g\VT\GetGadgetItemText
Prototype.s GetGadgetItemText_2(*g.GAD, pos, col, *a=0)
Global GetGadgetItemText_2.GetGadgetItemText_2=*g\VT\GetGadgetItemText

;extra parameter by ASM
!MOV EAX,0
!PUSH EAX
txt.s=GetGadgetItemText_1(*g, 0, 0)
Debug txt

;extra parameter (default value)
Debug GetGadgetItemText_2(*g, 0, 0)

ProcedureDLL.s GetGadgetItemText_(*g.GAD, pos, col, *a)
   ProcedureReturn "xxx"+GetGadgetItemText_2(*g, pos, col, *a)
EndProcedure

*g\VT\GetGadgetItemText=@GetGadgetItemText_()
Debug "txt.s="+GetGadgetItemText(10, 0, 1)
txt.s=GetGadgetItemText(10, 0, 1)
Debug "txt.s="+txt
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Post by hallodri »

All the functions return a string, have an additional parameter. This
parameter is for the string position. See above code. This parameter is
important, because nothing else can be passed. But not everything works.
Post Reply