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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:40:57+00:00 2026-05-24T02:40:57+00:00

In the structure of my program I’ve divided where it gets called from and

  • 0

In the structure of my program I’ve divided “where it gets called from” and “what gets done” into separate source files. As a matter of practicality, this allows me to compile the program as standalone or include it in a DLL. The code below is not the actual code but a simplified example that makes the same point.

There are 3 interacting components here: kernel mode program that loads my DLL, the DLL and its source files and the utility program with it’s source, that is maintained separately.

In the DLL form, the program is loaded as a thread. According to the kernel mode application vendor’s documentation, I loose the ability to call Win32 API functions after the initialization of the kernel program so I load the thread as an active thread (as opposed to using CREATE_SUSPENDED since I can’t wake it).

I have it monitor a flag variable so that it knows when to do something useful through an inelegant but functional:

while ( pauseThreadFlag ) Sleep(1000);

The up to 1 second lag is acceptable (the overall process is lengthy, and infrequently called) and doesn’t seem to impact the system.

In the thread source file I declare the variable as

volatile bool pauseThreadFlag = true;

Within the DLL source file I’ve declared

extern volatile bool pauseThreadFlag;

and when I am ready to have the thread execute, in the DLL I set

pauseThreadFlag = false;

I’ve had some difficulty in declaring std::string objects as volatile, so instead I have declared my parameters as global variables within the thread’s source file and have the DLL call setters which reside in the thread’s source. These strings would have been parameters if I could instantiate the thread at will.

(Missing from all of this is locking the variable for thread safety, which is my next “to do”)

This strikes me as a bad design … it’s functional but convoluted. Given the constraints that I’ve mentioned is there a better way to go about this?

I was thinking that a possible revision would be to use the LPVOID lpParams variable given at thread creation to hold pointers to the string objects, even though the strings will be empty when the thread is created, and access them directly from the thread, that way erasing the declarations, setters, etc in the thread program altogether? If this works then the pause flag could also be referenced there, and the extern declarations eliminated (but I think it still needs to be declared volatile to hint the optimizer).

If it makes any difference, the environment is Visual Studio 2010, C++, target platform Win32 (XP).

Thanks!

  • 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-24T02:40:58+00:00Added an answer on May 24, 2026 at 2:40 am

    I ended up removing the struct and replacing it with an object that encapsulates all the data. It’s a little hideous, being filled with getters and setters, but in this particular case I’m using the access methods to make sure that locks are properly set/unset.

    Using a void cast pointer to this object passed the object correctly and it seems quite stable.

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

Sidebar

Related Questions

My basic program structure is this: class B1 { vector <someStruct> aStruct; //some struct
I'm new to std::generate and have attempted to structure a program which uses it
I'm writing a console based program for my coursework, and am wondering how best
I'm trying to write a program that is just a little beyond my abilities.The
I am trying to open multiple processes in a Perl script on Windows. Program
I am using the M-V-VM architectural pattern. I want my program to have two
I have previously asked this question and since I already accepted an answer, I
For a simple command-line todo manager (that is to be implemented in C), this
Given a base class that is inherited by plethora of derived classes, and a
I am designing a GUI that has the following basic idea (similarly modeled after

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.