Board index » delphi » ** C calling vs. Pascal calling

** C calling vs. Pascal calling

Hi,

  I'm trying to use D3DRM in Delphi, and I seem to be running into
troubles.  When I call the method GetVertices in C I'd write

hresult = SourceMesh->GetVertices(&VCount, NULL, &NCount, NULL, &FaceSize,
                                                     NULL);
but in Delphi, I can't pass NULL, it wants D3DVECTOR.  It needs to be NULL
because the method returns the counts if everything is 0 and NULL.  In
Delphi the method is declared as

 function GetVertices(var lpVCount : DWORD; var lpVertices : D3DVECTOR;
                         var lpNCount : DWORD; var lpNormals : D3DVECTOR;
                         var lpFaceDataSize : DWORD; var lpFace_Dat :DWORD
) :             HRESULT; virtual ; stdcall ; abstract ;

So I set Vertices, Normals, and FaceData to nil.  The problem is I'm not
getting the correct info back.  This is how I'm calling it in Delphi.

    // Get Counts
    DXCheck(SourceMesh.GetVertices(Vcount, Vertices^[0], NCount,
                   Normals^[0], FaceSize, FaceData^[0]));

Any ideas where I'm going wrong?  

Daniel Spiess

 

Re:** C calling vs. Pascal calling


On 4 Jul 1997 00:38:30 GMT, "Daniel and Petra Spiess"

Quote
<dspi...@frii.com> wrote:

[deletia]

Quote
>but in Delphi, I can't pass NULL, it wants D3DVECTOR.  It needs to be NULL
>because the method returns the counts if everything is 0 and NULL.  In
>Delphi the method is declared as

> function GetVertices(var lpVCount : DWORD; var lpVertices : D3DVECTOR;
>                         var lpNCount : DWORD; var lpNormals : D3DVECTOR;
>                         var lpFaceDataSize : DWORD; var lpFace_Dat :DWORD
>) :                 HRESULT; virtual ; stdcall ; abstract ;
>So I set Vertices, Normals, and FaceData to nil.  The problem is I'm not
>getting the correct info back.  This is how I'm calling it in Delphi.

>    // Get Counts
>    DXCheck(SourceMesh.GetVertices(Vcount, Vertices^[0], NCount,
>                   Normals^[0], FaceSize, FaceData^[0]));

If I understand your situation, you need to pass either nil pointers
or arrays with zeros in the first elements for the function to behave
properly.  What you're doing here is passing the zeroth element of the
D3DVECTOR arrays; which is not the same thing as that element having
zero for a value, you need to assign THAT explicitly, something like:

  Vertices^[0] := 0 ;
  Normals^[0] := 0 ;
  FaceData^[0] := 0 ;

Then do your call.  Though I am puzzled as to why Delphi won't let you
pass Nil pointers (I'm assuming that D3DVECTOR is defined as some kind
of pointer type), what error do you get?

Quote
>Any ideas where I'm going wrong?  

>Daniel Spiess

HTH

Stephen Posey
slpo...@concentric.net

Re:** C calling vs. Pascal calling


Daniel and Petra Spiess <dspi...@frii.com> schrieb im Beitrag
<01bc881a$cc42fa40$4ef492d0@dspiess>...

Quote
> Hi,

>   I'm trying to use D3DRM in Delphi, and I seem to be running into
> troubles.  When I call the method GetVertices in C I'd write

> hresult = SourceMesh->GetVertices(&VCount, NULL, &NCount, NULL,
&FaceSize,
>                                                      NULL);
> but in Delphi, I can't pass NULL, it wants D3DVECTOR.  It needs to be
NULL
> because the method returns the counts if everything is 0 and NULL.  In
> Delphi the method is declared as

>  function GetVertices(var lpVCount : DWORD; var lpVertices : D3DVECTOR;
>                          var lpNCount : DWORD; var lpNormals : D3DVECTOR;
>                          var lpFaceDataSize : DWORD; var lpFace_Dat
:DWORD
> ) :                HRESULT; virtual ; stdcall ; abstract ;

> So I set Vertices, Normals, and FaceData to nil.  The problem is I'm not
> getting the correct info back.  This is how I'm calling it in Delphi.

>     // Get Counts
>     DXCheck(SourceMesh.GetVertices(Vcount, Vertices^[0], NCount,
>                    Normals^[0], FaceSize, FaceData^[0]));

> Any ideas where I'm going wrong?  

> Daniel Spiess

Hi Daniel,
I think my first answer didn't reach the newsgroup, but this one is better:
I started thinking after sending the first answer....

it is actually possible to fool the Delphi-compiler and pass a
Null-Variable, but not the way you tried it ;-)

type
  pD3DVECTOR = ^D3DVECTOR;
.....
    DXCheck(SourceMesh.GetVertices(Vcount, p3DVECTOR(nil)^, NCount,
                   p3DVECTOR(nil)^, FaceSize, pInteger(nil)^));

the other possibility is to redeclare the function using pointers instead
of vars

Dieter

--

If you like to email me please replace .xxx. in address

Other Threads