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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:30:48+00:00 2026-06-14T02:30:48+00:00

I am currently working on a project where I have to build a shell

  • 0

I am currently working on a project where I have to build a shell for a C++ dll, so a new C# GUI can use its functions.
However I got the following problem, in the C++ portion I have to create a new thread for specific reasons, and I want to pass an int array to the new thread.
Note that the values assigned to the array in the function in which this happens are gained from the C# portion of the code.

__declspec( dllexport ) void CreateReportPane(int &id, int &what)
{
    DWORD threadId; 
    int iArray[2] = { id, what};    

    HANDLE hThread = CreateThread( NULL, 0, CreateReportPaneThread, iArray, 0,  &threadId);
    if (hThread == NULL) 
    {           
        ExitProcess(3);
    }    
}

The problem arises in the new thread, I can reliably fetch the first value out of the array, but the 2nd value seems to be released, here is the code on the other side.

DWORD WINAPI CreateReportPaneThread(LPVOID lparam)
{
    int id, what;
    id = *(( int * )lparam);
    what = *(((int *)lparam)+1) ; 
    CreateReportPaneOriginal(id, what);

    return 0;
}

Is there any way to prevent the values in the array from getting released while not holding the original thread captive?
A big thank you in advance

  • 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-06-14T02:30:49+00:00Added an answer on June 14, 2026 at 2:30 am
    int iArray[2] = { id, what};    
    
    HANDLE hThread = CreateThread(...,CreateReportPaneThread, iArray, ...);
    

    The problem is that iArray is a local array which means this gets destroyed when the function CreateReportPane() returns. So what CreateReportPaneThread() refers to doesn’t exist. You get the first value just by chance. There is no such guarantee that you would get even the first value.

    Use dynamic array:

    int * iArray  = new int[2];
    iArray[0] = id;
    iArray[1] = what;
    
    HANDLE hThread = CreateThread(...,CreateReportPaneThread, iArray, ...);
    

    Remember to write deallocate the array once you’re done with it in CreateReportPaneThread:

    DWORD WINAPI CreateReportPaneThread(PVOID *data)
    {
         int *array = static_cast<int*>(data);
    
         int id = array[0], what = array[1];
    
         delete []array; //MUST DO IT to avoid memory leak!
    
         //rest of your code
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to objective C and currently working on a small project. I have
I currently use Ant to build Java software. However, all development that I have
I am currently working on a project where I have code that looks like
I am currently working on a project about calculations.I have done the main part
I am currently working on android project where I want to have a text
I am currently working on an android project and I have an activity, lets
I am currently working on grails project. I have created eight different plugins. Each
Im currently working on a grizzly, spring and jersey project and i have encountered:
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
On the project that I'm currently working I have a requirement to run a

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.