Create Structure Runtime
Posted: Thu Feb 19, 2009 12:27 am
Hi all,
In pb how i can create structure in runtime like array ?
In pb how i can create structure in runtime like array ?
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
DIM variablename.structurename(arraysize)
thanks but this is'nt my mean.Seymour Clufley wrote:Off the top of my head, I think it's:Code: Select all
DIM variablename.structurename(arraysize)
Code: Select all
Structure Variable
long.l
name.s
EndStructure
Structure ReturnVar
long.l
str.s
name.s
EndStructure
Global mem = AllocateMemory(1024)
Macro calling(call_type, return_type, func, arg)
If return_type = "str"
If call_type = "cdecl"
ret1.s = PeekS(CallCFunctionFast(func, arg))
Else
ret1.s = PeekS(CallFunctionFast(func, arg))
EndIf
ElseIf return_type = "long"
If call_type = "cdecl"
ret2.l = CallCFunctionFast(func, arg)
Else
ret2.l = CallFunctionFast(func, arg)
EndIf
EndIf
EndMacro
Procedure DllCall(lpFileName.s, lpProcName.s, List Parameters.s(), OutPut.s)
Protected DLL.l
mem = AllocateMemory(1024)
DLL = LoadLibrary_(@lpFileName)
If DLL
calling_func = GetProcAddress_(DLL, @lpProcName)
If calling_func
Dim Param.Variable(ListSize(Parameters()) - 1)
i = 0
ForEach Parameters()
Param(i)\name = Mid(Parameters(), 1, FindString(Parameters(), ":", 1) - 1)
Select Param(i)\name
Case "long" : Param(i)\long = Val(Mid(Parameters(), FindString(Parameters(), ":", 1) + 1))
EndSelect
i = i + 1
Next
call_type.s = Mid(OutPut, 1, FindString(OutPut, ":", 1) - 1)
ret_type.s = Mid(OutPut, FindString(OutPut, ":", 1) + 1)
If Param(0)\name = "long"
calling(call_type, ret_type, calling_func, Param(0)\long)
If ret_type = "str"
PokeS(mem, ret1)
ProcedureReturn
Else
PokeL(mem, ret2)
ProcedureReturn
EndIf
EndIf
EndIf
FreeLibrary_(DLL)
EndIf
EndProcedure
NewList par.s()
NewList par2.s()
AddElement(par())
par() = "long:0" ; #SM_CXSCREEN
AddElement(par2())
par2() = "long:1" ; #SM_CYSCREEN
DllCall("user32.dll", "GetSystemMetrics", par(), "stdcall:long")
Debug PeekL(mem)
DllCall("user32.dll", "GetSystemMetrics", par2(), "stdcall:long")
Debug PeekL(mem)