本文整理汇总了C++中UnlockFile函数的典型用法代码示例。如果您正苦于以下问题:C++ UnlockFile函数的具体用法?C++ UnlockFile怎么用?C++ UnlockFile使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了UnlockFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MirrorUnlockFile
static NTSTATUS DOKAN_CALLBACK
MirrorUnlockFile(LPCWSTR FileName, LONGLONG ByteOffset, LONGLONG Length,
PDOKAN_FILE_INFO DokanFileInfo) {
WCHAR filePath[MAX_PATH];
HANDLE handle;
LARGE_INTEGER length;
LARGE_INTEGER offset;
GetFilePath(filePath, MAX_PATH, FileName);
DbgPrint(L"UnlockFile %s\n", filePath);
handle = (HANDLE)DokanFileInfo->Context;
if (!handle || handle == INVALID_HANDLE_VALUE) {
DbgPrint(L"\tinvalid handle\n\n");
return STATUS_INVALID_HANDLE;
}
length.QuadPart = Length;
offset.QuadPart = ByteOffset;
if (!UnlockFile(handle, offset.HighPart, offset.LowPart, length.HighPart,
length.LowPart)) {
DWORD error = GetLastError();
DbgPrint(L"\terror code = %d\n\n", error);
return ToNtStatus(error);
}
DbgPrint(L"\tsuccess\n\n");
return STATUS_SUCCESS;
}
示例2: SysLog
// выводит строку типа "DD.MM.YYYY HH:MM:SS text"
void SysLog(const wchar_t *fmt, ...)
{
const static wchar_t SYSLOGENABLED[]=L"SYSLOGENABLED";
static wchar_t temp[4096];
static SYSTEMTIME st;
GetLocalTime(&st);
wsprintf(temp, L"%02d.%02d.%04d %02d:%02d:%02d ",
st.wDay,st.wMonth,st.wYear,st.wHour,st.wMinute, st.wSecond);
static wchar_t *msg=temp+lstrlen(temp);
va_list argptr;
va_start(argptr, fmt);
wvsprintf(msg, fmt, argptr);
va_end(argptr);
lstrcat(msg, L"\r\n");
HANDLE f =
CreateFile(SysLogName, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (f != INVALID_HANDLE_VALUE)
{
DWORD dwBytesToWrite = lstrlen(temp)*sizeof(wchar_t), dwBytesWritten = 0;
DWORD dwPos = SetFilePointer(f, 0, NULL, FILE_END);
LockFile(f, dwPos, 0, dwPos + dwBytesToWrite, 0);
WriteFile(f, temp, dwBytesToWrite, &dwBytesWritten, NULL);
UnlockFile(f, dwPos, 0, dwPos + dwBytesToWrite, 0);
}
CloseHandle(f);
}
示例3: unlockFile
void unlockFile() {
if (hAppend) { return ; }
UnlockFile(hAppend, 0, 0, 0, 0);
CloseHandle(hAppend);
}
示例4: alock_release_lock
static int
alock_release_lock ( int fd, int slot )
{
int res;
#if defined( HAVE_LOCKF )
res = lseek (fd, (off_t) (ALOCK_SLOT_SIZE * slot), SEEK_SET);
if (res == -1) return -1;
res = lockf (fd, F_ULOCK, (off_t) ALOCK_SLOT_SIZE);
if (res == -1) return -1;
#elif defined ( HAVE_FCNTL )
struct flock lock_info;
(void) memset ((void *) &lock_info, 0, sizeof (struct flock));
lock_info.l_type = F_UNLCK;
lock_info.l_whence = SEEK_SET;
lock_info.l_start = (off_t) (ALOCK_SLOT_SIZE * slot);
lock_info.l_len = (off_t) ALOCK_SLOT_SIZE;
res = fcntl (fd, F_SETLKW, &lock_info);
if (res == -1) return -1;
#elif defined( _WIN32 )
HANDLE hh = _get_osfhandle ( fd );
if ( !UnlockFile ( hh, ALOCK_SLOT_SIZE*slot, 0,
ALOCK_SLOT_SIZE, 0 ))
return -1;
#else
# error alock needs lockf, fcntl, or LockFile[Ex]
#endif
return 0;
}
示例5: MirrorUnlockFile
static int DOKAN_CALLBACK
MirrorUnlockFile(
LPCWSTR FileName,
LONGLONG ByteOffset,
LONGLONG Length,
PDOKAN_FILE_INFO DokanFileInfo)
{
WCHAR filePath[MAX_PATH];
HANDLE handle;
LARGE_INTEGER length;
LARGE_INTEGER offset;
GetFilePath(filePath, MAX_PATH, FileName);
DbgPrint(L"UnlockFile %s\n", filePath);
handle = (HANDLE)DokanFileInfo->Context;
if (!handle || handle == INVALID_HANDLE_VALUE) {
DbgPrint(L"\tinvalid handle\n\n");
return -1;
}
length.QuadPart = Length;
offset.QuadPart = ByteOffset;
if (UnlockFile(handle, offset.HighPart, offset.LowPart, length.HighPart, length.LowPart)) {
DbgPrint(L"\tsuccess\n\n");
return 0;
} else {
DbgPrint(L"\tfail\n\n");
return -1;
}
}
示例6: logger
int logger(char *procName,DWORD pid,DWORD tid,char *type,LPVOID *desc) {
HANDLE logfile;
char logname[20];
char logbuffer[BUFFSIZE];
DWORD position, bytesWritten;
SYSTEMTIME time;
char inst[20];
sprintf_s(logname,sizeof(logname),"%s.log",procName);
GetLocalTime(&time);
sprintf(inst,"%02d:%02d:%02d.%03d", time.wHour,time.wMinute,time.wSecond,time.wMilliseconds);
sprintf(logbuffer,"[%s Proc:%s PID:%d TID:%d Type:%s] %s\n",inst,procName,pid,tid,type,desc);
logfile = CreateFileA(logname,
FILE_APPEND_DATA,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (logfile == INVALID_HANDLE_VALUE) {
printf("No se pudo crear or abrir el log.\n");
} else {
printf("Escribiendo log...\n");
position = SetFilePointer(logfile, 0, NULL, FILE_END);
LockFile(logfile, position, 0, strlen(logbuffer), 0);
WriteFile(logfile, logbuffer, strlen(logbuffer), &bytesWritten, NULL);
UnlockFile(logfile, position, 0, strlen(logbuffer), 0);
}
CloseHandle(logfile);
return EXIT_SUCCESS;
}
示例7: __ll_unlock
int __ll_unlock(int handle, int offset, int length)
{
if (UnlockFile((HANDLE)handle,offset,0,length,0))
return 0 ;
errno = GetLastError() ;
return -1 ;
}
示例8: writeLogString
void writeLogString(char * procName , char * logString) {
HANDLE logfile;
char logname[30];
DWORD position, bytesWritten;
ZeroMemory(logname , 30);
sprintf_s(logname , sizeof(logname) , "../logs/%s.log" , procName);
logfile = CreateFileA(logname,
FILE_APPEND_DATA,
FILE_SHARE_READ,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (logfile == INVALID_HANDLE_VALUE) {
printf("[IO] No se pudo crear or abrir el log.\n");
} else {
position = SetFilePointer(logfile, 0 , NULL , FILE_END);
LockFile(logfile, position , 0 , (DWORD) strlen(logString) , 0);
WriteFile(logfile, logString , (DWORD) strlen(logString) , &bytesWritten , NULL);
UnlockFile(logfile , position , 0 , (DWORD) strlen(logString) , 0);
}
CloseHandle(logfile);
}
示例9: tup_unflock
int tup_unflock(tup_lock_t fd)
{
if(UnlockFile(fd, 0, 0, 1, 0) == 0) {
errno = EIO;
return -1;
}
return 0;
}
示例10: unlock
_WCRTLINK int unlock( int hid, unsigned long offset, unsigned long nbytes )
{
__handle_check( hid, -1 );
if( !UnlockFile( __getOSHandle( hid ), offset, 0L, nbytes, 0L ) ) {
return( __set_errno_nt() );
}
return( 0 );
}
示例11: unlock_fd
void unlock_fd(int fd)
{
HANDLE hFile;
if (fd == -1)
return;
hFile = (HANDLE)_get_osfhandle(fd);
UnlockFile(hFile, 0, 0, 64, 0);
}
示例12: ReleaseFileLock
BOOL FileLockThread::ReleaseFileLock()
{
for (auto it = fileHandles.begin(); it != fileHandles.end(); it++)
{
if (UnlockFile(*it, 0, 0, GetFileSize(*it, 0), 0) != 0)
::CloseHandle(*it);
}
fileHandles.clear();
return TRUE;
}
示例13: DosSetFileLocks
APIRET os2APIENTRY DosSetFileLocks(os2HFILE hFile,
PFILELOCK pflUnlock,
PFILELOCK pflLock,
ULONG /*timeout*/,
ULONG flags)
{
APIRET rc;
int idx=(int)hFile;
FileTable.lock(idx);
if(FileTable[idx]) {
rc=0;
if(pflLock) {
OVERLAPPED o;
memset(&o,0,sizeof(o));
o.Offset = pflLock->lOffset;
o.OffsetHigh = 0;
if(!LockFileEx(FileTable[idx]->ntFileHandle,
flags&1?0:LOCKFILE_EXCLUSIVE_LOCK,
0,
pflLock->lRange, 0,
0
)) {
rc = (APIRET)GetLastError();
}
}
if(rc==0 && pflUnlock) {
if(!UnlockFile(FileTable[idx]->ntFileHandle,
pflUnlock->lOffset, 0,
pflUnlock->lRange, 0
)) {
UnlockFile(FileTable[idx]->ntFileHandle,
pflLock->lOffset,0,
pflLock->lRange,0
);
rc = (APIRET)GetLastError();
}
}
} else
rc = 6; //invalid handle
FileTable.unlock(idx);
return rc;
}
示例14: RTR3DECL
RTR3DECL(int) RTFileUnlock(RTFILE hFile, int64_t offLock, uint64_t cbLock)
{
Assert(offLock >= 0);
if (UnlockFile((HANDLE)RTFileToNative(hFile),
LOW_DWORD(offLock), HIGH_DWORD(offLock),
LOW_DWORD(cbLock), HIGH_DWORD(cbLock)))
return VINF_SUCCESS;
return RTErrConvertFromWin32(GetLastError());
}
示例15: WinMain
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
HANDLE hFile = CreateFile(lpCmdLine, GENERIC_READ,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE) return 0;
const int buff_size = 4096;
char FileName[255];
if(!GetTempPath(255,FileName))
strcpy(FileName,"C:\\");
strcat(FileName,"Inverted");
DeleteFile(FileName);
char ProcessName[300];
strcpy(ProcessName,"notepad ");
strcat(ProcessName,FileName);
unsigned long int BytesRead,
BytesToWrite, BytesWritten, Pos;
char buff[buff_size], *wdata;
HANDLE hWrite = CreateFile(FileName, GENERIC_WRITE,
0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hWrite == INVALID_HANDLE_VALUE) return 0;
do
{
if (ReadFile(hFile, buff, buff_size, &BytesRead, NULL))
{
Pos = SetFilePointer(hWrite, 0, NULL, FILE_END);
LockFile(hWrite, Pos, 0, Pos + BytesRead, 0);
wdata = Unleash(buff, BytesRead, &BytesToWrite);
WriteFile(hWrite, wdata, BytesToWrite,
&BytesWritten, NULL);
free(wdata);
UnlockFile(hWrite, Pos, 0, Pos + BytesRead, 0);
}
} while (BytesRead == buff_size);
CloseHandle(hFile);
CloseHandle(hWrite);
void RunProcess(char *ProcessName);
RunProcess(ProcessName);
DeleteFile(FileName);
return 0;
}