tags:

views:

50

answers:

1

Hey,

Im writing a DLL and I want to write some data to a file (150k+)

The problem is - WriteFile is not writing everything it should write

It looks like the thread gets terminated before WriteFile finish its work.

any ideas ? thanks

+3  A: 

If you exit your process before the thread completes, all other threads will be terminated (from ExitProcess):

Exiting a process causes the following:

  1. All of the threads in the process, except the calling thread, terminate their execution without receiving a DLL_THREAD_DETACH notification.
  2. The states of all of the threads terminated in step 1 become signaled.
  3. The entry-point functions of all loaded dynamic-link libraries (DLLs) are called with DLL_PROCESS_DETACH.
  4. After all attached DLLs have executed any process termination code, the ExitProcess function terminates the current process, including the calling thread.
  5. The state of the calling thread becomes signaled.
  6. All of the object handles opened by the process are closed.
  7. The termination status of the process changes from STILL_ACTIVE to the exit value of the process.
  8. The state of the process object becomes signaled, satisfying any threads that had been waiting for the process to terminate.

You will need to explicitly wait for the thread executing WriteFile to complete, usually via WaitForSingleObject(thread handle, ...).

MSN
Also note that if the process is terminated (rather than exited), it's even worse -- `DLL_PROCESS_DETACH` is not called in that case.
Billy ONeal