recortebordes 0 Newbie Poster

Hi everyone!

I have an interesting problem in borland c++. I have to write a DLL, which contains one function. The function's aim is to create a window with a progress bar, and a close button disabled. Then it downloads a microcontroller firmware via serial port to a device. After the completion of the download, the close button is enabled, and a message is shown in the window (e.g. Download complete, Timeout Error, etc).

My code reflecting the implementation is here:

TDownloadDialog *DownloadDialog;  // the window with progress bar and button
                                                      // global because pThread handles its prog bar

int iDllFunction() {
  SerialPortThread* pThread;
  int iReturn;
  
  DownloadDialog = new TDownloadDialog(NULL);
  pThread = new SerialPortThread(false);  // thread constructing with CreateSuspended = false

  pThread->OnTerminate = DownloadDialog->EndOfDownload; // end of download routine displays message and enables close button (function pointer setting)
  DownloadDialog->ShowModal();

  iReturn = pThread->iGetStatus;
  delete pThread;

  return iReturn;
}

I've made a test application that uses this DLL function. It has a button, and when you click it, its OnClick event handler calls iDllFunction. It's working fine, although I've found a strange bug: if I move the mouse cursor out of the test application form right after I call the DLL function, the threads OnTerminate method doesn't execute. When I move back the mouse into the test application form's area, the OnTerminate method executes.

I dunno what this error can be, but I tried one thing: I removed the whole dll thing and made the test application and the dll function into 1 project, and there is no bug, the OnTerminate method always executes.

But it's not the solution, because I have a specification that this window must be implemented in a DLL.

Can anyone help me?

Thx,
Dave