structures and procedures
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
structures and procedures
hello i got a structure with some data in. and. i need to pass this structure through a procedure
like..
;my structure
poo.BLABLA
poo\size = sizeof(BLABLA)
poo\blaa = 356
poo\hooo = 495
;passing the structure to the procedure
myprocedure(poo)
is this correct? because im doing so and i get undesired effects
like..
;my structure
poo.BLABLA
poo\size = sizeof(BLABLA)
poo\blaa = 356
poo\hooo = 495
;passing the structure to the procedure
myprocedure(poo)
is this correct? because im doing so and i get undesired effects
re
Hi,
you need to use a 'pointer' to the structure and pass the address of the structure through the pointer to the procedure.
you need to use a 'pointer' to the structure and pass the address of the structure through the pointer to the procedure.
Code: Select all
;my Structure
Structure BLABLA
size.l
blaa.l
hooo.l
EndStructure
Procedure myprocedure(*arg.BLABLA); *arg sets up a pointer to a variable of type BLABLA
*arg\blaa = 10
;etc.
EndProcedure
poo.BLABLA; Set up a variable of type BLABLA.
poo\size = SizeOf(BLABLA)
poo\blaa = 356
poo\hooo = 495
Debug "poo\blaa = " + Str(poo\blaa); Displays the value of 356.
myprocedure(@poo); Calls the procedure and passes the ADDRESS OF the variable poo.
Debug "poo\blaa now = " + Str(poo\blaa); Now displays the new value of 10.
I may look like a mule, but I'm not a complete ass.
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
well theres no need really
I got the structure and some stuff in it.
now, i want to pass the structure via my procedure, and from there, to a value in a function im calling from a dll
even if i gave you the code, i cant give you the dll.
so i thought its pretty much logical as for needing to paste source here. sorry if i dont make sense i thought i was.
I got the structure and some stuff in it.
now, i want to pass the structure via my procedure, and from there, to a value in a function im calling from a dll
even if i gave you the code, i cant give you the dll.
so i thought its pretty much logical as for needing to paste source here. sorry if i dont make sense i thought i was.
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
Here:
made an example of my problem
made an example of my problem
Code: Select all
;HOW can I pass the structure to myprocedure correctly?!?!
#meh = 232
Procedure MyProcedure(val1,val2,theval)
; of course we wont call this because it will crash
;bla = CallFunction(1,"blabla",val1,val2,theval)
Debug val1
Debug val2
Debug theval ; the important one
EndProcedure
Structure HELLO
hmmm.l
blabla.l
num.l
info.l
EndStructure
hi.HELLO ;struct
hi\hmmm = 1
hi\blabla = #meh
hi\num = 4234
hi\info = 34234234
MyProcedure(324,22,hi)
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
First thing is that by attempting to debug the value of a structure, you'll only ever access the memory address of the structure.
E.g. if the variable 'hi' refers to a structure variable, then the command
will simply display the address of the structure in memory and not any of it's data fields.
To display the contents of the structure you need to display each field in turn; e.g.
The second thing is that in your procedure definition
the variable 'theval' by default is a type 'long' variable; NOT a structure.
You need to declare this, not as a structure, but as a pointer to a structure as follows:
The third problem is that you now need to put the structure declaration before the procedure declaration etc.
E.g. if the variable 'hi' refers to a structure variable, then the command
Code: Select all
debug hi
To display the contents of the structure you need to display each field in turn; e.g.
Code: Select all
debug hi\num
Code: Select all
Procedure MyProcedure(val1,val2,theval)
You need to declare this, not as a structure, but as a pointer to a structure as follows:
Code: Select all
Procedure MyProcedure(val1,val2,*theval.HELLO)
Code: Select all
;HOW can I pass the structure to myprocedure correctly?!?!
#meh = 232
Structure HELLO
hmmm.l
blabla.l
num.l
info.l
EndStructure
Procedure MyProcedure(val1,val2,*theval.HELLO)
; of course we wont call this because it will crash
;bla = CallFunction(1,"blabla",val1,val2,theval)
Debug val1
Debug val2
Debug *theval\hmmm ; the important one
EndProcedure
hi.HELLO ;struct
hi\hmmm = 1
hi\blabla = #meh
um = 4234
hi\info = 34234234
MyProcedure(324,22,@hi)
I may look like a mule, but I'm not a complete ass.
re
Ah, I see, think I'm being thicker than a walrus sandwich today!
If all you need do is pass the address of the structure to the dll then your code looks okay. I guess the focus then should be upon the dll itself.
Without knowing more about the library it's difficult to advise.
If all you need do is pass the address of the structure to the dll then your code looks okay. I guess the focus then should be upon the dll itself.
Without knowing more about the library it's difficult to advise.
I may look like a mule, but I'm not a complete ass.
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
lib ? its opengl32 !
by the way I believe I need to send all the data in the structure.. but how would I. I thought about passing the values inside the procedure with the pointer trick and then making a value with all the values inside ?
but i dont know how opengl32 manages this
its for the function 1590848448 (wglSetPixelFormat)
by the way I believe I need to send all the data in the structure.. but how would I. I thought about passing the values inside the procedure with the pointer trick and then making a value with all the values inside ?
but i dont know how opengl32 manages this
its for the function 1590848448 (wglSetPixelFormat)
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
1590848448????doodlemunch wrote:its for the function 1590848448 (wglSetPixelFormat)

viewtopic.php?p=86116#86116
Good programmers don't comment their code. It was hard to write, should be hard to read.
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
SetPixelFormat is a gdi-function, not an opengl function.
Did I miss something?
However, calling the function directly from the dll is the same.
Did I miss something?
However, calling the function directly from the dll is the same.
Code: Select all
gdi32.l = OpenLibrary(#PB_Any, "gdi32.dll")
opengl32.l = OpenLibrary(#PB_Any, "opengl32.dll")
*SetPixelFormat = IsFunction(gdi32, "SetPixelFormat")
*ChoosePixelFormat = IsFunction(gdi32, "ChoosePixelFormat")
*wglMakeCurrent = IsFunction(opengl32, "wglMakeCurrent")
*wglCreateContext = IsFunction(opengl32, "wglCreateContext")
pfd.PIXELFORMATDESCRIPTOR
ZeroMemory_(@pfd, SizeOf(PIXELFORMATDESCRIPTOR))
pfd\nSize = SizeOf(PIXELFORMATDESCRIPTOR)
pfd\nVersion = 1
pfd\dwFlags = #PFD_DRAW_TO_WINDOW | #PFD_SUPPORT_OPENGL | #PFD_DOUBLEBUFFER
pfd\iPixelType = #PFD_TYPE_RGBA
pfd\cColorBits = 32
pfd\cDepthBits = 16
pfd\iLayerType = #PFD_MAIN_PLANE
hdc.l = GetDC_(OpenWindow(0,0,0,640,480,#PB_Window_SystemMenu,"OpenGL"))
pixelFormat.l = CallFunctionFast(*ChoosePixelFormat, hdc, @pfd)
CallFunctionFast(*SetPixelFormat, hdc, pixelFormat, @pfd)
CallFunctionFast(*wglMakeCurrent, hdc, CallFunctionFast(*wglCreateContext, hdc))
While EventID<>#PB_Event_CloseWindow
EventID=WaitWindowEvent()
Delay(10)
Wend
CloseLibrary(opengl32)
CloseLibrary(gdi32)
End
Good programmers don't comment their code. It was hard to write, should be hard to read.
-
- Enthusiast
- Posts: 237
- Joined: Tue Apr 05, 2005 11:20 pm
i know i got a dillema because i saw the same function on both opengl32 and gdi32 look
from opengl wglSetPixelFormat 1590848448
from gdi GdiSetPixelFormat 2012498864
of course im in the need of the WGL one because im working with opengl and as far as i know thats the correct one? or i missed something again? :roll:
from opengl wglSetPixelFormat 1590848448
from gdi GdiSetPixelFormat 2012498864
of course im in the need of the WGL one because im working with opengl and as far as i know thats the correct one? or i missed something again? :roll: