In dealing with DLL parameters and structures specifically
there are a few considerations.

It is not a good idea to use mema unless there
is a really good reason for it. Instead consider
stack or locale variables, as it is done in C; and the 
advantages the same auto-release, faster, etc.
So instead of
    a=. mema 10,...
use
    a=. 10$' '

Structs can be approached differently. One is
mneumonic encoding and typed accessors as done in 
"task" scripts
   open'task'

However, later realizing that most stuct members, as call
arguments are machine words, i.e. integers, it is better
to represent structs as flat int arrays. Then a cover
function would convert float to and from int.
   f2i=: (_2) 3!:4 (1) 3!:5 ]
   f2i^:_1 f2i _1.5
_1.5

As with v-table indices (see pcall addon examples), 
it is a good idea to enumerate the indices of struct 
entries for mneumonic access.

   struct A { int a,b,c; }  would become
   'A_a A_b A_c'=: i.3

then allocating

   a=. 3$_1

and accessing

   a=. 125 A_a}a   NB. a.a = 125;
   echo A_b{a      NB. echo(a.b);

Int and other arrays are nicely understood by
the "*" modifier of cd, as used with ">".


--- Mikhail Mikhailov <[EMAIL PROTECTED]> wrote:

> Hello,
> 
> I'm trying to port my application from IBM APL2 to J and have the following
> question:
> how can I call a DLL function having a pointer to a structure as an argument
> (or as an result)?
> 
> For example:
> bool AdvancedCollision(VECTOR3D* pStart, VECTOR3D* pEnd, COLLISIONRESULT*
> retResult);
> 
> where VECTOR3D is:
> 
> typedef struct {
>  float x;
>  float y;
>  float z;
> } VECTOR3D;
> 
> and COLLISIONRESULT is:
> 
> typedef struct {
>         VECTOR3D vCollisionNormal;
>         VECTOR3D vCollisionImpact;
>         float fDistance;
>         float fU;
>         float fV;
>         int iFaceindex;
>         int iGroupIndex;
>         bool bHasCollided;
>         int iEntityID;
>         int iMeshID;
>         int iLandscapeID;
>         int iBoneID;
>         float fTexU;
>         float fTexV;
>     } COLLISIONRESULT;
> 
> Should I create the structures using mema/memw first and then pass the
> pointers? Is there a straight way?
> AdvancedCollision function writes the new values for COLLISIONRESULT. Again,
> should I use memr to read the contents of COLLISIONRESULT or there is a way
> to get a nested array right away?
> APL2 allows to specify a pointer to a structure directly (I use QuadNA).
> 
> Thank you in advance,
> Mik.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 



       
____________________________________________________________________________________Yahoo!
 oneSearch: Finally, mobile search 
that gives answers, not web links. 
http://mobile.yahoo.com/mobileweb/onesearch?refer=1ONXIC
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to