Jump to content

Pointer to a struct Type, or pointer to a pointer?


Recommended Posts

My questions is this: I have a dllCall expecting a struct to be passed. The struct is 3 separate floats, not arrays. I build them like so:

Local $StartVectorStruct = DllStructCreate("float;float;float")
    DllStructSetData($StartVectorStruct, 1 , $a_StartVector[0])
    DllStructSetData($StartVectorStruct, 2 , $a_StartVector[1])
    DllStructSetData($StartVectorStruct, 3 , $a_StartVector[2])

My question is this: when I pass it to the DllCall, do I want to pass ptr* or float* to pass the struct? or is it just a ptr?

;This
DllCall($_irrDll, "none:cdecl", "IrrGetCollisionPoint", "float*", DllStructGetPtr($StartVectorStruct))
;Or This...
DllCall($_irrDll, "none:cdecl", "IrrGetCollisionPoint", "ptr*", DllStructGetPtr($StartVectorStruct))
;Or even this?
DllCall($_irrDll, "none:cdecl", "IrrGetCollisionPoint", "ptr", DllStructGetPtr($StartVectorStruct))

Also, what is the reason for struct indices starting at 1, instead of 0?

Edited by JRowe
Link to comment
Share on other sites

I would say the third one since DllStructGetPtr returns a pointer to a structure. Regardless of your intent you have created a structure then sending it in, the help file specifes the same thing but with ints.

float* is a pointer to a float which DllStructGetPtr does not return.

ptr* is a pointer to a pointer which would mean DllStructGetPtr would have to return a ponter to another pointer for that to be valid.

As for the second question, pass :idea:

DllCall($_irrDll, "none:cdecl", "IrrGetCollisionPoint", "float*", DllStructGetPtr($StartVectorStruct, 1))

This might work also for the first element within the structure.

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Link to comment
Share on other sites

Link to comment
Share on other sites

integer = IrrGetCollisionPoint ( start as IRR_VECTOR, line_end as IRR_VECTOR, collision group as irr_selector, collision point as IRR_VECTOR )

The actual code I ended up with is:

Func _IrrGetCollisionPoint($a_StartVector, $a_EndVector, $h_CollisionGroup)
    Local $StartVectorStruct = DllStructCreate("float;float;float")
    DllStructSetData($StartVectorStruct, 1, $a_StartVector[0])
    DllStructSetData($StartVectorStruct, 2, $a_StartVector[1])
    DllStructSetData($StartVectorStruct, 3, $a_StartVector[2])
    Local $EndVectorStruct = DllStructCreate("float;float;float")
    DllStructSetData($EndVectorStruct, 1, $a_EndVector[0])
    DllStructSetData($EndVectorStruct, 2, $a_EndVector[1])
    DllStructSetData($EndVectorStruct, 3, $a_EndVector[2])

    Local $CollisionVectorStruct = DllStructCreate("float;float;float")
    DllCall($_irrDll, "none:cdecl", "IrrGetCollisionPoint", "ptr", DllStructGetPtr($StartVectorStruct), "ptr", DllStructGetPtr($EndVectorStruct), "ptr", $h_CollisionGroup, "ptr", DllStructGetPtr($CollisionVectorStruct))
    Local $result[3] = [DllStructGetData($CollisionVectorStruct, 1), DllStructGetData($CollisionVectorStruct, 2), DllStructGetData($CollisionVectorStruct, 3)]
    Return $result
EndFunc

An AutoIt version of a vector, then, would just be an array of 3 floats.

edit: 0.o

Looks like I have some revising to do.

Edited by JRowe
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...