某文件是否被打开

_wsopen_s MSDN

头文件:

#include <io.h> 
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <share.h>

/*****************************************************************************
	* @brief    : 生成的放在工程路径下的doc文件是否被打开
	* @author   : mahongkai
	* @date     : 2019/4/24 16:55
	* @version  : ver 1.0
	* @inparam  : 文件名
	* @outparam : TRUE,被打开; FALSE,没有被打开
	*****************************************************************************/
BOOL bOpenedDocXml(LPCTSTR strDocxName)
{
	if (strDocxName != NULL)
	{
        // 获取文件所在的工程所在路径
		wchar_t *wProPath = getProjectPathXml();
		if (wProPath != NULL)
		{
			wcscat(wProPath, _T("\\"));
			wcscat(wProPath, strDocxName);
			int  fh, numread;
			errno_t err = _wsopen_s(&fh, wProPath, _O_WRONLY, _SH_DENYNO, _S_IREAD | _S_IWRITE);
			if (err == EACCES)	 // _Open并 _O_EXCL标志指定,但filename已存在。
			{
				CString str1 = _T("即将关闭 '");
				CString str2 = wProPath;
				CString str3 = _T(" ' 文件,如需要请另存!!!");
				CString str = str1 + str2 + str3;										 
				MessageBoxW(NULL, str, _T("关闭文档"), MB_OK);
				delete[] wProPath;
				wProPath = NULL;
				return TRUE;
			}
			else
			{
				//close(fh);
				delete[] wProPath;
				wProPath = NULL;
				return FALSE;
			}
		}
		
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Ma_Hong_Kai

微信 2936729162

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值