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 6679905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:24:47+00:00 2026-05-26T04:24:47+00:00

MSDN states : … Therefore, when returning a DLL-created string or floating-point array, you

  • 0

MSDN states:

… Therefore, when returning a DLL-created string or floating-point
array, you have the following choices:

  • Set a persistent pointer to a dynamically allocated buffer, return the pointer. On the next call to the function (1) check that the
    pointer is not null, (2) free the resources allocated on the previous
    call and reset the pointer to null, (3) reuse the pointer for a newly
    allocated block of memory. …

I get the following error dialog when I call free:

MSVC++ Debug Library HEAP CORRUPTION DETECTED: after Normal
block(#135) at 0x……. CRT detected that the application wrote to
memory after end of healp buffer.

Here’s my code:

FP * g_FP;

extern "C" FP * __stdcall xllFill(long rows, long cols) {

    if (g_FP != NULL) {
        free(g_FP);
        g_FP = NULL;
    }
    g_FP = (FP *)malloc(rows * cols * sizeof(double) + 2 * sizeof(unsigned short int));

    for (int i = 0; i < rows * cols; i++) {
        (*g_FP).data[i] = (double)i;
    }
    (*g_FP).rows = (unsigned short int)rows;
    (*g_FP).cols = (unsigned short int)cols;
    return g_FP;
}

I’m a bit rusty on C++ but I can’t figure for the life of me why this isn’t working.

  • 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-26T04:24:48+00:00Added an answer on May 26, 2026 at 4:24 am

    FP is declared like this:

    typedef struct _FP
    {
        unsigned short int rows;
        unsigned short int columns;
        double array[1];        /* Actually, array[rows][columns] */
    } FP;
    

    You are assuming that FP is packed and contains no padding. I don’t know how XLLs are meant to be compiled but I think it is very likely that there is padding between columns and array to arrange that array is 8 byte aligned. With default settings, MSVC returns 16 for sizeof(FP) which supports my hypothesis.

    Change your allocation to this:

    g_FP = malloc((rows*cols-1)*sizeof(double) + sizeof(*g_FP));
    

    Even if this isn’t the cause of your problem, the allocation above is the logically correct form.

    Otherwise I cannot see anything wrong with your code. I think you could be more explicit in initialising g_FP to NULL but that’s a minor point.

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

Sidebar

Related Questions

I have set the ActiveDirectoryMembershipProvider connectionProtection attribute to secure, according to MSDN documentation states
MSDN states that String.Intern retrieves the system's reference to the specified String and String.IsInterned
MSDN states the following SortedSet(T).Add Method : If Count is less than the capacity
I have some misunderstanding about the gslice function. Definition from MSDN states: gslice defines
This MSDN article states that: An isolation level has connection-wide scope, and once set
In the following MSDN page it states the encryption algorithms that are supported by
The msdn documentation about order preservation in PLINQ states the following about ForAll() .
The MSDN states that the method returns true if the method is successfully queued;
This article on MSDN states that you can use as many try catch blocks
When does script added to the page with Page.ClientScript.RegisterStartupScript() actually run? MSDN states "when

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.