Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 264395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:40:55+00:00 2026-05-11T22:40:55+00:00

I’m using Delphi to make an XLL add-in for Excel, which involves making a

  • 0

I’m using Delphi to make an XLL add-in for Excel, which involves making a lot of calls to the Excel4v function of xlcall32.dll. However, as I’m guessing very few Delphi experts here have worked with that specific API, I’m hoping that the problem might have been observed in other APIs too.

In C, specifically in the xlcall.h file that comes with the Microsoft Excel 2007 XLL SDK, Excel4v is defined as:

int pascal Excel4v(int xlfn, LPXLOPER operRes, int count, LPXLOPER opers[]);

In Delphi I’m using:

function Excel4v(xlfn: Integer; operRes: LPXLOPER; count: Integer;
    opers: array of LPXLOPER): Integer; stdcall; external 'xlcall32.dll';

LPXLOPER is a pointer to a struct (in C) or record (in Delphi).

I’ve been doing my homework on declaring C functions in Delphi (this excellent article was a great help), and I think I’m declaring Excel4v properly. However, calls from Delphi code into that function cause exceptions (“access violation…” is what I keep seeing) unless they are followed by the following line:

asm pop sink; end;

Where “sink” is defined somewhere as an integer.

I have no clue about assembly… So there’s no way would I have thought to try fixing the exceptions with “asm pop sink; end;”. But “asm pop sink; end;” does indeed fix the exceptions. I first saw it used in this useful article on making XLLs using Delphi. Here’s the most relevant quote:

“From Delphi the big stumbling block
with add-ins is the extra parameter
after the return address on the stack.
This comes free with every call to
Excel. I’ve never found out what it
holds, but so long as you throw it
away, your add-in will work fine. Add
the line asm pop variable, end; after
every call where variable can be any
global, local or object variable that
is at least 4 bytes long- integer is
fine. To repeat- THIS MUST BE INCLUDED
after every Excel4v call. Otherwise
you are constructing a time-bomb.”

Basically I want to understand what’s actually happening, and why. What could be causing a Win32 function to return an “extra parameter after the return address on the stack”, and what does that actually mean?

Might there be another way to fix this, e.g. with a different compiler option or a different way of declaring the function?

And is there anything risky about calling “asm pop sink; end;” after every call to Excel4v…? It seems to work fine, but, as I don’t understand what’s going on, it feels a little dangerous…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T22:40:55+00:00Added an answer on May 11, 2026 at 10:40 pm

    I don’t believe it’s pascal vs stdcall – they are very similar calling conventions and should not result in a mismatched stack on function exit.

    From the referenced article,

    This would indeed be a very nice
    syntax, but it is not the same as the
    above array definition. Array-of
    parameters are open array parameters.
    They may look like any array, and they
    do accept any array, but they get an
    extra (hidden) parameter, which holds
    the highest index in the array (the
    High value). Since this is only so in
    Delphi, and not in C or C++, you’d
    have a real problem. (See also my
    article on open arrays), since the
    real number of parameters wouldn’t
    match.

    You’re getting the extra “highest array index” parameter being passed to the function. This is an int and has to be cleaned up when the function exits so that you don’t wind up with a corrupted stack and crash. The article indicates how to pass arrays to C functions.

    Something like:

    type
     PLPXLOPER  = ^LPXLOPER;
    

    And pass PLPXLOPER as the last parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 138k
  • Answers 138k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Since you tagged your question with cocos2d I guess you'll… May 12, 2026 at 7:28 am
  • Editorial Team
    Editorial Team added an answer How often do you run across a situation where you… May 12, 2026 at 7:28 am
  • Editorial Team
    Editorial Team added an answer just changed from filter to servlet and worked just fine… May 12, 2026 at 7:28 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.