2.为什么要调用CloseHandle

cpp99 2003-10-09 10:43:18
1.这代码运行通不过
2.为什么要调用CloseHandle

int main(int argc, char *argv[])
{
HMODULE module = GetModuleHandle(0);
CHAR buf[MAX_PATH];
GetModuleFileName(module, buf, sizeof buf);
CloseHandle(HANDLE(4));
__asm {
lea eax, buf
push 0
push 0
push eax
push ExitProcess
push module
push DeleteFile
push UnmapViewOfFile
ret
}
return 0;
}
...全文
32 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
panzhaoping 2003-10-09
  • 打赏
  • 举报
回复
这涉及到操作系统中的引用问题,当系统分配一个handle后,其中的引用会自加1的,
你可以看看com技术,所以在用完了,要把handle给close掉。
zhusunme 2003-10-09
  • 打赏
  • 举报
回复
加#include <windows.h>就行了

This function closes an open object handle.
CloseHandle invalidates the specified object handle, decrements the object’s handle count, and performs object retention checks. After the last handle to an object is closed, the object is removed from the system. Persistent objects such as databases and files will remain in storage, but must be re-opened to be accessed again.

69,374

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧