文件访问 我要对一个文件实现:一个程序(进程)读,一个程序(进程)写。请教怎么实现 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用共享方式打开即可,例如用CreateFile打开文件,指定dwShareMode为FILE_SHARE_READ|FILE_SHARE_WRITE。 不同进程操作同一个文件最好做同步等,Mutex等互斥,这样可以保证数据访问正确等 CreateFile与 open有什么区别。有人说用open不好,但是CreateFile应该是用open和sopen实现的啊。请大家帮分析一下。 open、sopen都是调用CreateFile实现的。CreateFile是操作系统的API,C/C++库函数最终都是要调用系统API来实现输入/输出的。 open、sopen都是调用CreateFile实现的?????open sopen应该是C的把.应该比CreateFile底层哦? 你自己写段程序,调用open函数,在CreateFile函数上设置一个断点,看会不会运行到。 多线程读,使用临界区同步#include <afxmt.h>void WriteString(CString strLog){ CString strLogPath = ""; char *pszPath; DWORD nlen = 256; pszPath = new char[nlen]; memset(pszPath,0,sizeof(char)*nlen); GetModuleFileName(NULL,pszPath,nlen); strLogPath = pszPath; strLogPath = strLogPath.Left(strLogPath.ReverseFind('\\')+1); strLogPath = strLogPath + "ErrorInfo.log"; if(pszPath) { delete []pszPath; pszPath = NULL; } CFile cf; OFSTRUCT of; HFILE hf = OpenFile(strLogPath,&of,OF_EXIST); if(hf==-1) { cf.Open(strLogPath,CFile::modeCreate|CFile::modeWrite); } else { cf.Open(strLogPath,CFile::modeWrite); cf.SeekToEnd(); } int iTempValue = GetLastError(); CString strWrite = ""; strWrite = strLog + "\r\n"; CCriticalSection sl; sl.Lock(); cf.Write(strWrite.GetBuffer(strWrite.GetLength()),strWrite.GetLength()); sl.Unlock(); cf.Close();} 关于IsDialogMessage函数的一点疑问,好久没来了,顺便散分。。。 单击程序的客户区的矩形出现相应的提示信息 WinSock中的端口问题。 用VC做工具搞网络编程,什么参考书好呀?大家来讨论一下! Gdi+ 的问题 急~~~ 请帮忙看看 DLL这样写为什么不能返回值呢?(看里面代码) 不会设置vc环境,55555 如何获得存放在邮件服务器上的邮件信息…… 请问对于Debug版本的程序怎样禁止程序结束的Dump操作? VC读取txt文件代码 截获全局鼠标钩子,在右键弹出菜单时,如何弹出自己的菜单?
open sopen应该是C的把.应该比CreateFile底层哦?
#include <afxmt.h>
void WriteString(CString strLog)
{
CString strLogPath = "";
char *pszPath;
DWORD nlen = 256;
pszPath = new char[nlen];
memset(pszPath,0,sizeof(char)*nlen);
GetModuleFileName(NULL,pszPath,nlen);
strLogPath = pszPath;
strLogPath = strLogPath.Left(strLogPath.ReverseFind('\\')+1);
strLogPath = strLogPath + "ErrorInfo.log";
if(pszPath)
{
delete []pszPath;
pszPath = NULL;
}
CFile cf;
OFSTRUCT of;
HFILE hf = OpenFile(strLogPath,&of,OF_EXIST);
if(hf==-1)
{
cf.Open(strLogPath,CFile::modeCreate|CFile::modeWrite);
}
else
{
cf.Open(strLogPath,CFile::modeWrite);
cf.SeekToEnd();
}
int iTempValue = GetLastError();
CString strWrite = "";
strWrite = strLog + "\r\n";
CCriticalSection sl;
sl.Lock();
cf.Write(strWrite.GetBuffer(strWrite.GetLength()),strWrite.GetLength());
sl.Unlock();
cf.Close();
}