Solved

NT 4.0/Delphi 2 c dll & record structure problem

Posted on 1997-06-21
6
294 Views
Last Modified: 2010-04-03
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;
End;

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

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

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
invalid.

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
difference.  

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

Thanx in advance,
L
0
Comment
Question by:ls3
  • 3
  • 3
6 Comments
 
LVL 1

Expert Comment

by:ygolan
ID: 1337355
L,

Try changing the record declaration to

 DV_TPT = PACKED record


0
 

Author Comment

by:ls3
ID: 1337356
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.
L
0
 
LVL 1

Expert Comment

by:ygolan
ID: 1337357
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ls3
ID: 1337358
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;
cdecl;

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

0
 

Author Comment

by:ls3
ID: 1337359
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?
0
 
LVL 1

Accepted Solution

by:
ygolan earned 200 total points
ID: 1337360
I've posted this as "answer", so you can give me the points if you choose so.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 212
Delphi 2 51
Why is there a Difference between the SQL String and using the Parameter ? 7 31
Graphics32 under Delphi 10.1 Berlin 2 40
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now