Page 1 of 2
structures and procedures
Posted: Tue Apr 12, 2005 6:04 pm
by doodlemunch
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
re
Posted: Tue Apr 12, 2005 6:33 pm
by srod
Hi,
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.
Posted: Tue Apr 12, 2005 6:46 pm
by doodlemunch
hi thanks
what i need to do is pass poo to the procedure and from there to a dll function. i believe im doing it wrong because even tho the function returns 1 the result is not the expected.
Posted: Tue Apr 12, 2005 6:49 pm
by srod
Can you post some code?
Posted: Tue Apr 12, 2005 6:53 pm
by doodlemunch
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.
Posted: Tue Apr 12, 2005 7:03 pm
by doodlemunch
Here:
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)
Posted: Tue Apr 12, 2005 7:07 pm
by doodlemunch
as you can see the dll function needs the correct structure data .. if not it wont work as expected. and thats my problem i dont know how to send it the correct data.
Posted: Tue Apr 12, 2005 7:18 pm
by srod
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
Code: Select all
Procedure MyProcedure(val1,val2,theval)
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:
Code: Select all
Procedure MyProcedure(val1,val2,*theval.HELLO)
The third problem is that you now need to put the structure declaration before the procedure declaration etc.
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)
re
Posted: Tue Apr 12, 2005 7:25 pm
by srod
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.
Posted: Tue Apr 12, 2005 7:29 pm
by doodlemunch
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)
Posted: Tue Apr 12, 2005 7:34 pm
by doodlemunch
for example on ChoosePixelFormat i pass the address of the same structure and works nice so far
but with this other function SetPixelFormat doesnt seem to work the same way
Posted: Tue Apr 12, 2005 7:35 pm
by traumatic
doodlemunch wrote:its for the function 1590848448 (wglSetPixelFormat)
1590848448????
viewtopic.php?p=86116#86116
Posted: Tue Apr 12, 2005 7:50 pm
by doodlemunch
thx but no it does not help
i dont want to use the function like that i want to call it directly from the opengl dll thats the joy
and so i dont know how to pass the structure i gave the address but it doesnt work- even that the function returns 1 it does not work correctly
Posted: Tue Apr 12, 2005 7:55 pm
by traumatic
SetPixelFormat is a gdi-function, not an opengl function.
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
Posted: Tue Apr 12, 2005 8:05 pm
by doodlemunch
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: