Create Structure Runtime

Just starting out? Need help? Post your questions and find answers here.
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Create Structure Runtime

Post by Peyman »

Hi all,
In pb how i can create structure in runtime like array ?
Seymour Clufley
Addict
Addict
Posts: 1265
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Post by Seymour Clufley »

Off the top of my head, I think it's:

Code: Select all

DIM variablename.structurename(arraysize)
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Post by Peyman »

Seymour Clufley wrote:Off the top of my head, I think it's:

Code: Select all

DIM variablename.structurename(arraysize)
thanks but this is'nt my mean.
i want create structure on runtime, something like this :
http://www.autoitscript.com/autoit3/doc ... Create.htm
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

PB is a compiler language, no script, not interpreted.

a structure does only exist while compiling.
it's nothing more than a descriptive kind of offset, to make access easier for the programmer.
at runtime, the structure itself does no longer exist but only the offsets.

Coordinate.POINT\Y will become (adress of Coordinate + 4)

so, there is not only no way but also no use in creating a structure at runtime.
oh... and have a nice day.
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Post by Peyman »

thanks Kaeru Gaman, i know PB is a compiler Autoit & ... created in c++ and execute codes on runtime like a interpreter, How they do it ?
c++ is a compiler. do you have any info about structure, i want know more about it.

And another question i want create dllcall or load library like http://www.autoitscript.com/autoit3/doc ... llCall.htm, how can i do this nobody have any idea.
Thanks for help.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Peyman
Enthusiast
Enthusiast
Posts: 203
Joined: Mon Dec 24, 2007 4:15 pm
Location: Iran

Post by Peyman »

thanks ts-soft, but my mean is aanother dllcall like dllcall dynamic.
i create a examp but i know my algo isnt good for dllcall please see my code and give me an idea for create it

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