当前位置: 首页>>代码示例>>C++>>正文


C++ UnlockFile函数代码示例

本文整理汇总了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;
}
开发者ID:cnhup,项目名称:dokany,代码行数:31,代码来源:mirror.c

示例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);
}
开发者ID:Maximus5,项目名称:evil-programmers,代码行数:33,代码来源:syslog.cpp

示例3: unlockFile

void unlockFile() {

  if (hAppend) { return ; }

  UnlockFile(hAppend, 0, 0, 0, 0);
  CloseHandle(hAppend);
}
开发者ID:obabywawa,项目名称:logsystem,代码行数:7,代码来源:launcher.cpp

示例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;
}
开发者ID:ayoubsabbar,项目名称:openldap,代码行数:32,代码来源:alock.c

示例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;
	}
}
开发者ID:jdstroy,项目名称:dokany,代码行数:33,代码来源:mirror.c

示例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;
    }
开发者ID:kronleuchter85,项目名称:tomateperita,代码行数:34,代码来源:commons.c

示例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 ;
}
开发者ID:doniexun,项目名称:OrangeC,代码行数:7,代码来源:llunlock.c

示例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);
    }
开发者ID:kronleuchter85,项目名称:tomateperita,代码行数:27,代码来源:logging.c

示例9: tup_unflock

int tup_unflock(tup_lock_t fd)
{
	if(UnlockFile(fd, 0, 0, 1, 0) == 0) {
		errno = EIO;
		return -1;
	}
	return 0;
}
开发者ID:CodeFred,项目名称:tup,代码行数:8,代码来源:lock_file.c

示例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 );
}
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:9,代码来源:unlckwnt.c

示例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);
}
开发者ID:DanielT,项目名称:NitroHack,代码行数:10,代码来源:files.c

示例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;
}
开发者ID:shharn,项目名称:mysources,代码行数:10,代码来源:FileLockThread.cpp

示例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;
}
开发者ID:ErisBlastar,项目名称:osfree,代码行数:42,代码来源:filemgr1.cpp

示例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());
}
开发者ID:sobomax,项目名称:virtualbox_64bit_edd,代码行数:11,代码来源:fileio-win.cpp

示例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;
}
开发者ID:hansongjing,项目名称:Old-Projects,代码行数:53,代码来源:1.cpp


注:本文中的UnlockFile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。