gpt4 book ai didi

c++ - 使用 DLL 写入文件

转载 作者:行者123 更新时间:2023-11-28 01:12:12 25 4
gpt4 key购买 nike

我正在编写一个 DLL,我想将一些数据写入一个文件 (150k+)

问题是 - WriteFile 没有写它应该写的所有内容

看起来线程在 WriteFile 完成其工作之前就终止了。

有什么想法吗?谢谢

最佳答案

如果您在线程完成之前退出您的进程,所有其他线程都将终止(来自 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.

您需要显式等待执行 WriteFile 的线程完成,通常是通过 WaitForSingleObject(thread handle, ...)

关于c++ - 使用 DLL 写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2222815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com