NT 4.0/Delphi 2 c dll & record structure problem

Hello Delphians,

I am having a rather unique problem, that I hope someone else has run
into.  I have a 3rd party library of DLL's (completely documented
no less!) that were compiled/linked with the extern "C" prefix.  Most of these
routines take very large structures as parameters which I have been
able to covert into Delpi2/Pascal without a problem & they work fine.
All but this one & it is the smallest structure that is giving me the
most pain.

The C header defines dx_tpt as:

typedef struct dv_tpt  DV_TPT;

struct dv_tpt {
   unsigned short tp_type;      
   unsigned short tp_termno;  
   unsigned short tp_length;    
   unsigned short tp_flags;      
   unsigned short tp_data;      
   unsigned short rfu;          
   DV_TPT   *tp_nextp;          

This should convert fairly easily to Delphi as:

Type   pDV_TPT               = ^DV_TPT;
       DV_TPT                = record
       tp_type:                    Word;  
       tp_termno:                  Word;
       tp_length:                  Word;  
       tp_flags:                   Word;  
       tp_data:                    Word;  
       rfu:                        Word;  
       tp_nextp:                   pDV_TPT;

one of the routines (this one clears the structure) is defined as:
function  dx_clrtpt(var dvtpt: DV_TPT; cnt: Integer):     Integer;

What happens is this: dx_clrtpt clears everything except for tp_type &

If I pass the structure to a routine that is suppose to do something
more than clear it, I get an internal message saying the structure is

The vendor is no help and told me I should write my app using C or C++
(yeah right, like I have a year to do that! :-)

I also tried setting up the structure as SmallInt's & there was no

If anyone can think of anything I may be doing wrong...I'd sure
appreciate a nudge!!

Thanx in advance,
Who is Participating?
ygolanConnect With a Mentor Commented:
I've posted this as "answer", so you can give me the points if you choose so.

Try changing the record declaration to

 DV_TPT = PACKED record

ls3Author Commented:
Let me add...
I have tried Packed, Alignment On & Off, using far before the cdecl and a few other silly things that made no difference.
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Can you post the original C function definition ?

If you didn't yet, I suggest that you also write a small C program demonstrating to your self that this particular function works as expected it C, and then translate the entire program to Delphi.
ls3Author Commented:
At the top of my original note is the structure.

Here is the c prototype for dx_clrtpt:

extern int dx_clrtpt( DV_TPT *tptp, int size );

I have also tried defining this to Delphi using pointers too:

function dx_clrtpt(dvtpt: pDV_TPT; cnt: Integer): Integer;

The results were the same.  I appreciate anything else you can think of!!

ls3Author Commented:
Stop the presses...  I just wrote a little C++ program.  The bug is with my vendor as it did exactly the same thing as Delphi.  

Now how do I change this note to closed & how do I get you some points for taking the time to help me?
All Courses

From novice to tech pro — start learning today.