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

  • SEARCH
  • Home
  • 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 7673047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:25:22+00:00 2026-05-31T16:25:22+00:00

I try to pass a structure as a parameter. Global structure: struct ThreadParams {

  • 0

I try to pass a structure as a parameter.

Global structure:

struct ThreadParams 
 {
  HWND window;
  LIB::ServiceContainer* mrt;
 };

In the main thread:

ThreadParams threadparams;
threadparams.window = (HWND) GetSafeHwnd();
threadparams.mrt = m_rt;

CWinThread* pthread1;
pthread1 = (CWinThread*) AfxBeginThread(Thread1,(LPVOID)&threadparams,THREAD_PRIORITY_NORMAL,0,0,0);

Outside the class:

UINT Thread1(LPVOID lp)
{
 ThreadParams* threadparams = (ThreadParams*) lp;

     HWND hmainWindow = threadparams->window; 
 LIB::ServiceContainer* m_rt = threadparams->mrt;

}

Although it compiles fine, I get an error at runtime (it is an unexpected error) and I guess that I mess up with the pointer m_rt. Do you see any obvious mistakes?

  • 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-31T16:25:24+00:00Added an answer on May 31, 2026 at 4:25 pm
    ThreadParams threadparams;
    

    Note that if it is a local variable, and the function which declares it returns after creating the thread, then the thread refers to an object which doesn’t exist anymore, as the local variable gets destroyed when the function returns. If that is the case, then create a new instance using new instead as:

    ThreadParams * pthreadparams = new ThreadParams();
    

    and pass it to the thread, so that it will exist even if the function which creates the thread returns. Of course, when you’re done with it, you’ve to delete it manually.

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

Sidebar

Related Questions

I have a get-parameter with name controller . When I try to pass it
I try to pass a pointer of a structure which is given me as
What is the difference between ',' and 'as' in except statements, eg: try: pass
If you try to pass the username/password to OpenVPN from a file via the
My compiler behaves oddly when I try to pass a fixed-size array to a
I'm working on a program where I try to pass parameters by reference. I'm
I have a jax-rpc web service. When i try to pass xml to the
Given the email address: Jim <jim@example.com> If I try to pass this to MailAddress
I need to pass a structure to a method, but it will not always
I've got a structure as follows: typedef struct { std::wstring DevAgentVersion; std::wstring SerialNumber; }

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.