[solved] GetGadgetItemText .... C/C++ returned string
[solved] GetGadgetItemText .... C/C++ returned string
How to return string without ProcedureReturn ?
Last edited by eddy on Thu Dec 18, 2008 7:47 pm, edited 2 times in total.

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,...
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Here's mine:
Code: Select all
Procedure sample(*a.String)
*a\S = "abcdef"
EndProcedure
Define a.String
sample(@a)
Debug a\S
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
- Rook Zimbabwe
- Addict
- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Using justRook Zimbabwe wrote:Um... use a GLOBAL variable to hold the $ ??? Then you could change it in multiple procedures and viola!
Code: Select all
Shared s.s

This is a short example to understand this problem:
Where is the string result ?
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.

pseudo
pb desc
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;
}
Code: Select all
Test,() -
String | Unicode | DebuggerCheck
I plan to customize a PB gadget.
Like that :
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)

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


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
