Link to home
Start Free TrialLog in
Avatar of mikepj
mikepjFlag for Canada

asked on

Stack trouble during DLL call?

Am I missing something here?  The stack needs to be "adjusted" by 8 bytes in Delphi after returning from the call but I have no idea why!

  asm
    pop EAX;
    pop EAX;
  end;

double* are pushed onto the stack as a DWORD pointer
BYTE are pushed onto the stack as values
double is pushed onto the stack as 8 bytes of data

Thank you for your help!
MP

Here's the Visual C++ DLL function export:

int _stdcall GetPoly(
     BYTE p_bTypeOfData,
     BYTE p_bAnode,
     BYTE p_bFilterType,
     double p_fThickness,
     double p_fkVp,
     double* p_dC0,
     double* p_dC1,
     double* p_dC2,
     double* p_dC3,
     double* p_dC4,
     double* p_fkVpLo,
     double* p_fkVpHi,
     double* p_fTotFiltrLo,
     double* p_fTotFiltrHi);

// here's my Delphi 5 declaration for the DLL function
function GetPoly(
     iTypeOfData,
     iAnodeType,
     iFilterType:byte;
     dThickness,dKV:double;
     var dPoly0,dPoly1,dPoly2,dPoly3,dPoly4:double;
     var dKVLow,dKVHigh:double;
     var dTotalFiltrLow, dTotalFiltrHigh:double):integer;
     StdCall;
     external 'MyDLL';

Here's my call for the function:

Result:=GetPoly(
     iType,
     iAnode,
     iFilter,
     dThickness,
     dKV,
     dPoly1,
     dPoly2,
     dPoly3,
     dPoly4,
     dPoly5,
     dKVLow,
     dKVHigh,
     dLow,
     dHigh);

// now I need to remove 8 bytes from the stack if things are going to work properly.

ASKER CERTIFIED SOLUTION
Avatar of AvonWyss
AvonWyss
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mikepj

ASKER

Oops!  You're both correct; when creating the EE question I made a mistake.  It is using:

var dPoly0, dPoly1, dPoly2, dPoly3, dPoly4: double;

At one point I had just to make sure (I know better) I had tried this:

var dPoly0:double; var dPoly1:double; var dPoly2:double...

I had tried initializing the polys initially because I wasn't sure at the beginning that I was having stack problems.  It didn't help.

I have done a similar call to another DLL and this was no problem.

I think I'm going to e-mail the authors of the DLL; they sent me new source code but I think it must not match exactly the source they have sent me.  Will advise...

Thanks for your replies!
MP
Avatar of mikepj

ASKER

I forgot to mention that I have corrected the question text.

Since StdCall does have the caller responsible for cleaning up the stack, this makes me wonder whether a mismatch in the DLL (the DLL parameter list being different than the source they provided) could cause this or whether that's not possible.  Any opinions?

I've also wondered if this could possibly be a Delphi 5.01 bug...doubtful.

Thanks!
MP
Avatar of robert_marquardt
robert_marquardt

Check if double does not convert to extended.
With stdcall the called function cleans up the stack.
Can you send me the C header? robert_marquardt@gmx.de
Avatar of mikepj

ASKER

Robert,

The header is in the question.

THanks,
MP
The complete C header file please.
Avatar of mikepj

ASKER

The file only contains exports and this is the only export of interest.  For privacy and the proprietary interests of my client, I can't give the rest.  It has no #includes, #define, pragma, etc.  Only exports similar to the one of interest.

int _stdcall GetPoly(BYTE p_bTypeOfData, BYTE p_bAnode, BYTE p_bFilterType, double p_fThickness, double p_fkVp, double* p_dC0, double* p_dC1, double* p_dC2, double* p_dC3, double* p_dC4, double* p_fkVpLo, double* p_fkVpHi, double* p_fTotFiltrLo, double* p_fTotFiltrHi);

The .def file contains the following (other export removed):

LIBRARY MyLib
DESCRIPTION DLL FOR MyLib CARD

EXPORTS
     GetPoly     @14
Avatar of mikepj

ASKER

The DLL didn't match the source.  It works now.

Thanks,
MP
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ and Refund

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
Thankyou for the resolution of this question.

Paul (pnh73)
EE Cleanup Volunteer
Avatar of mikepj

ASKER

thank you!
Request for PAQ and Refund will be removed.

Paul (pnh73)
EE Cleanup Volunteer