本文介绍了获取当前进程的句柄时CreateFile失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

char CurrentPath[MAX_PATH] = {0};
GetModuleFileName(NULL,CurrentPath,MAX_PATH);
char BaseNameA[MAX_PATH] = {0};
GetBaseNameFromPath(CurrentPath,BaseNameA);
if(hFile==NULL)
{
    hFile = CreateFile(CurrentPath,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
    if(hFile==INVALID_HANDLE_VALUE)
        MessageBox(0,"hFile Failed!",0,0);
}





您好!



上面的代码是随机失败的(有时它完美地运行,有时它会报告hFile Failed!)。我不太明白为什么它有时会失败。



也许我应该使用C库来打开当前进程的文件?



也许有人知道更可靠的解决方案?



我想要做的就是打开当前进程的本地文件我我在。



谢谢!



Hello!

The code above is failing randomly (sometimes it works perfectly, other times it reports "hFile Failed!"). I don't quite understand why it fails at times.

Perhaps I should use C-libraries for opening the current process's file?

Perhaps someone knows a more reliable solution?

Again all I'm trying to do is open the local file of the current process I'm in.

Thank you!

推荐答案


这篇关于获取当前进程的句柄时CreateFile失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-16 05:38