Page 1 of 1

Create Structure Runtime

Posted: Thu Feb 19, 2009 12:27 am
by Peyman
Hi all,
In pb how i can create structure in runtime like array ?

Posted: Thu Feb 19, 2009 12:31 am
by Seymour Clufley
Off the top of my head, I think it's:

Code: Select all

DIM variablename.structurename(arraysize)

Posted: Thu Feb 19, 2009 12:38 am
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

Posted: Thu Feb 19, 2009 1:05 am
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.

Posted: Fri Mar 06, 2009 4:09 pm
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.

Posted: Fri Mar 06, 2009 4:22 pm
by ts-soft

Posted: Fri Mar 06, 2009 9:53 pm
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)