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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:24:55+00:00 2026-06-01T09:24:55+00:00

For testing an existing application I wrote a dll that can be loaded into

  • 0

For testing an existing application I wrote a dll that can be loaded into our simulation application. All is working just fine until I want to reset the existing application from within the dll. Although the main() is restarted, it seems that the memory is not reset/initialized.
The goal is to change as little as possible in the existing application, so actually I don’t want to rewrite the application to initialize its variables at startup. Besides that, all local static variables also keep their old values.

Below a sample of how I call the existing application from within the dll.

void TimerThread::Run(void)
{
  while(true)
  {
    if ((nullptr != mpMainThread) && (mpMainThread->ThreadState == System::Threading::ThreadState::Stopped))
    {
      // Cleanup MainThread when thread has stopped
      delete mpMainThread;
      mpMainThread = nullptr;
    }

    if (nullptr == mpMainThread)
    {
      // (Re)create MainThread in which the existing application is executed
      mpMainThread = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(&Main));
      mpMainThread->Priority = System::Threading::ThreadPriority::Highest;
      mpMainThread->Start();
    }
    dtStartTime = System::DateTime::Now;           // Keep track when started.
    if (nullptr != mpMainThread)
    {
      //Simulate timertick in existing application
      main_callback_timer_elapsed();
    }

    dtEndTime = System::DateTime::Now;
    iDuration = dtEndTime->Millisecond - dtStartTime->Millisecond;  // Determine execution time.
    System::Threading::Thread::Sleep(((TIMER_INTERVAL - iDuration) > 0) ? (miInterval - iDuration) : 0);    // Set sleep time depending on time spent
  }
}

void TimerThread::Main(void)
{
  main();     // Run main off existing application
}

void TimerThread::Reset(void)
{
  mpMainThread->Abort();      // Reset existing application by aborting MainThread
}

The main of the existing application is quite common. Below an indication of the main().

int main(void)
{
  static char test = 0;

  init_stuff();

  while(true)
  {
    test = 1;

    do_stuff();
    while(!timer_tick)
    {
      check_timer();
    }
    timer_tick = FALSE;
  }
}

The static test variable is initialized at 0 and set to 1 in the infinite loop. When the application is reset from within the dll, the main restarts, but the test variable keeps the value 1. Obviously I want this variable to be reset to 0 when I reset the application.

Any ideas?

  • 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-01T09:24:57+00:00Added an answer on June 1, 2026 at 9:24 am

    If the native DLL doesn’t provide a function to reset its state then you will have to unload the DLL and then reload it. If you are using implicit linking that’s not possible. You have to use explicit linking: LoadLibrary, GetProcAddress etc.

    I’m assuming that the native code is contained in a separate DLL. If that’s not the case then you are completely stuck.

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

Sidebar

Related Questions

I have an existing database that has some testing data into and I'm interested
I'm working on implementing dynamic loading of Pages into a existing Silverlight application. So
I am testing an existing application in the Windows 8 consumer preview and it
I'm strongly considering adding unit testing to an existing project that is in production.
I have an existing ASP.net 3.5 web application. This is tested and working in
I have an existing asp.net webforms application that I would like to add some
I'm working on an existing Java web application (HTML/CSS/JS/JSP/Servlets and Java classes in this
I've recently taken an existing ASP.NET 3.5 web forms application that was upgraded to
I need to take an existing winforms application and drop into an event tracing
We're testing our ClickOnce deployed application internally on IIS (Internet Information Services), but we're

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.