if (hFile == INVALID_HANDLE_VALUE)
05. {
06. MessageBox(NULL, _T("文件打开失败!"), _T("Tip"), MB_OK);
07. return -1;
08. }
这里 return -1 是返回给了谁?
源代码如下
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HANDLE hFile = CreateFile(_T("D:\\VC驿站ok.txt"), GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, _T("文件打开失败!"), _T("Tip"), MB_OK);
return -1;
}
DWORD dwWrited = 0;
wchar_t szbuf[] = _T("我是VC驿站的粉丝!");
static const BYTE unicodeHead[] = { 0xFF, 0xFE }; //unicode文件头文件
WriteFile(hFile, unicodeHead, sizeof(unicodeHead), &dwWrited, NULL);
BOOL bWriteOK = WriteFile(hFile, szbuf, sizeof(szbuf), &dwWrited, NULL);
CloseHandle(hFile);
return 0;
}
本帖最后由 yoobaby 于 2022-4-24 11:56 编辑
用于说明程序的退出状态。如果返回0,则代表程序正常退出;返回其它数字的含义则由系统决定。通常,返回非零代表程序异常退出。
可以说是返回给操作系统的。
你编译完你的程序,然后同目录下建个strat.bat 内容如下:
- 你的exe.exe
- @echo %errorlevel%
- pause
复制代码
如果文件未找到,他就会返回你的那个-1
|