您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ CreateFileA函数代码示例

51自学网 2021-06-01 20:14:29
  C++
这篇教程C++ CreateFileA函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中CreateFileA函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateFileA函数的具体用法?C++ CreateFileA怎么用?C++ CreateFileA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了CreateFileA函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: open

int File::read(){    if (len)        return 0;               // already read the file#if POSIX    size_t size;    ssize_t numread;    int fd;    struct stat buf;    int result = 0;    char *name;    name = this->name->toChars();    //printf("File::read('%s')/n",name);    fd = open(name, O_RDONLY);    if (fd == -1)    {        //printf("/topen error, errno = %d/n",errno);        goto err1;    }    if (!ref)        ::free(buffer);    ref = 0;       // we own the buffer now    //printf("/tfile opened/n");    if (fstat(fd, &buf))    {        printf("/tfstat error, errno = %d/n",errno);        goto err2;    }    size = (size_t)buf.st_size;    buffer = (unsigned char *) ::malloc(size + 2);    if (!buffer)    {        printf("/tmalloc error, errno = %d/n",errno);        goto err2;    }    numread = ::read(fd, buffer, size);    if (numread != size)    {        printf("/tread error, errno = %d/n",errno);        goto err2;    }    if (touchtime)        memcpy(touchtime, &buf, sizeof(buf));    if (close(fd) == -1)    {        printf("/tclose error, errno = %d/n",errno);        goto err;    }    len = size;    // Always store a wchar ^Z past end of buffer so scanner has a sentinel    buffer[size] = 0;           // ^Z is obsolete, use 0    buffer[size + 1] = 0;    return 0;err2:    close(fd);err:    ::free(buffer);    buffer = NULL;    len = 0;err1:    result = 1;    return result;#elif _WIN32    DWORD size;    DWORD numread;    HANDLE h;    int result = 0;    char *name;    name = this->name->toChars();    h = CreateFileA(name,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,        FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,NULL);    if (h == INVALID_HANDLE_VALUE)        goto err1;    if (!ref)        ::free(buffer);    ref = 0;    size = GetFileSize(h,NULL);    buffer = (unsigned char *) ::malloc(size + 2);    if (!buffer)        goto err2;    if (ReadFile(h,buffer,size,&numread,NULL) != TRUE)        goto err2;    if (numread != size)        goto err2;//.........这里部分代码省略.........
开发者ID:NativeAPI,项目名称:dmd,代码行数:101,


示例2: clear

voidTeDecoderFile::init(){	clear();	// First open the file	m_hFile = CreateFileA(		params_.fileName_.c_str(),	// File name		GENERIC_READ | GENERIC_WRITE,	// Read-write		FILE_SHARE_READ		| FILE_SHARE_WRITE,		// Allow sharing-- we're only doing a quick scan		NULL,					// No security attributes		OPEN_EXISTING,			// Only open an existing file		0,						// Ignore file attributes		NULL);					// Ignore hTemplateFile	if (m_hFile == INVALID_HANDLE_VALUE) 			return ;		// could not open file// Get the file's size	m_dwSize = GetFileSize(m_hFile, NULL);	if (m_dwSize == 0xffffffff)	{		m_hFile = NULL;		return ;	}// Allocate buffer to get raster line from file	long mBufferSize = params_.ncols_;	if (params_.interleaving_ == TeRasterParams::TePerPixel)		mBufferSize *= params_.nBands();	switch (params_.dataType_[0]) {	case (TeUNSIGNEDCHAR):		m_buffer = new unsigned char[mBufferSize];		break;	case (TeCHAR) :		m_buffer = new char[mBufferSize];		break;	case (TeUNSIGNEDSHORT):		m_buffer = new unsigned short[mBufferSize];		break;	case (TeSHORT):		m_buffer = new short[mBufferSize];		break;	case (TeUNSIGNEDLONG):		m_buffer = new unsigned long[mBufferSize];		break;	case (TeLONG):		m_buffer = new long[mBufferSize];		break;	case (TeFLOAT):		m_buffer = new float[mBufferSize];		break;	case (TeDOUBLE):		m_buffer = new double[mBufferSize];		break;    default:        break;	}	if ( m_buffer == NULL )		return ;	else		return ;		}
开发者ID:Universefei,项目名称:Terralib-analysis,代码行数:68,


示例3: SetFile

BOOL SetFile(PCHAR pszPath){    BOOL bGood = TRUE;    HANDLE hOld = INVALID_HANDLE_VALUE;    HANDLE hNew = INVALID_HANDLE_VALUE;    PDETOUR_BINARY pBinary = NULL;    CHAR szOrg[MAX_PATH];    CHAR szNew[MAX_PATH];    CHAR szOld[MAX_PATH];    szOld[0] = '/0';    szNew[0] = '/0';    StringCchCopyA(szOrg, sizeof(szOrg), pszPath);    StringCchCopyA(szNew, sizeof(szNew), szOrg);    StringCchCatA(szNew, sizeof(szNew), "#");    StringCchCopyA(szOld, sizeof(szOld), szOrg);    StringCchCatA(szOld, sizeof(szOld), "~");    printf("  %s:/n", pszPath);    hOld = CreateFileA(szOrg,                       GENERIC_READ,                       FILE_SHARE_READ,                       NULL,                       OPEN_EXISTING,                       FILE_ATTRIBUTE_NORMAL,                       NULL);    if (hOld == INVALID_HANDLE_VALUE) {        printf("Couldn't open input file: %s, error: %d/n",               szOrg, GetLastError());        bGood = FALSE;        goto end;    }    hNew = CreateFileA(szNew,                       GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS,                       FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);    if (hNew == INVALID_HANDLE_VALUE) {        printf("Couldn't open output file: %s, error: %d/n",               szNew, GetLastError());        bGood = FALSE;        goto end;    }    if ((pBinary = DetourBinaryOpen(hOld)) == NULL) {        printf("DetourBinaryOpen failed: %d/n", GetLastError());        goto end;    }    if (hOld != INVALID_HANDLE_VALUE) {        CloseHandle(hOld);        hOld = INVALID_HANDLE_VALUE;    }    {        BOOL bAddedDll = FALSE;        DetourBinaryResetImports(pBinary);        if (!s_fRemove) {            if (!DetourBinaryEditImports(pBinary,                                         &bAddedDll,                                         AddBywayCallback, NULL, NULL, NULL)) {                printf("DetourBinaryEditImports failed: %d/n", GetLastError());            }        }        if (!DetourBinaryEditImports(pBinary, NULL,                                     ListBywayCallback, ListFileCallback,                                     NULL, NULL)) {            printf("DetourBinaryEditImports failed: %d/n", GetLastError());        }        if (!DetourBinaryWrite(pBinary, hNew)) {            printf("DetourBinaryWrite failed: %d/n", GetLastError());            bGood = FALSE;        }        DetourBinaryClose(pBinary);        pBinary = NULL;        if (hNew != INVALID_HANDLE_VALUE) {            CloseHandle(hNew);            hNew = INVALID_HANDLE_VALUE;        }        if (bGood) {            if (!DeleteFileA(szOld)) {                DWORD dwError = GetLastError();                if (dwError != ERROR_FILE_NOT_FOUND) {                    printf("Warning: Couldn't delete %s: %d/n", szOld, dwError);                    bGood = FALSE;                }            }            if (!MoveFileA(szOrg, szOld)) {                printf("Error: Couldn't back up %s to %s: %d/n",                       szOrg, szOld, GetLastError());//.........这里部分代码省略.........
开发者ID:qeedquan,项目名称:game_format_dumpers,代码行数:101,


示例4: return

template <typename PointT> intpcl::PCDWriter::writeBinaryCompressed (const std::string &file_name,                                        const pcl::PointCloud<PointT> &cloud){  if (cloud.points.empty ())  {    throw pcl::IOException ("[pcl::PCDWriter::writeBinaryCompressed] Input point cloud has no data!");    return (-1);  }  int data_idx = 0;  std::ostringstream oss;  oss << generateHeader<PointT> (cloud) << "DATA binary_compressed/n";  oss.flush ();  data_idx = static_cast<int> (oss.tellp ());#if _WIN32  HANDLE h_native_file = CreateFileA (file_name.c_str (), GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);  if (h_native_file == INVALID_HANDLE_VALUE)  {    throw pcl::IOException ("[pcl::PCDWriter::writeBinaryCompressed] Error during CreateFile!");    return (-1);  }#else  int fd = pcl_open (file_name.c_str (), O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);  if (fd < 0)  {    throw pcl::IOException ("[pcl::PCDWriter::writeBinaryCompressed] Error during open!");    return (-1);  }#endif  // Mandatory lock file  boost::interprocess::file_lock file_lock;  setLockingPermissions (file_name, file_lock);  std::vector<pcl::PCLPointField> fields;  size_t fsize = 0;  size_t data_size = 0;  size_t nri = 0;  pcl::getFields (cloud, fields);  std::vector<int> fields_sizes (fields.size ());  // Compute the total size of the fields  for (size_t i = 0; i < fields.size (); ++i)  {    if (fields[i].name == "_")      continue;        fields_sizes[nri] = fields[i].count * pcl::getFieldSize (fields[i].datatype);    fsize += fields_sizes[nri];    fields[nri] = fields[i];    ++nri;  }  fields_sizes.resize (nri);  fields.resize (nri);   // Compute the size of data  data_size = cloud.points.size () * fsize;  //////////////////////////////////////////////////////////////////////  // Empty array holding only the valid data  // data_size = nr_points * point_size   //           = nr_points * (sizeof_field_1 + sizeof_field_2 + ... sizeof_field_n)  //           = sizeof_field_1 * nr_points + sizeof_field_2 * nr_points + ... sizeof_field_n * nr_points  char *only_valid_data = static_cast<char*> (malloc (data_size));  // Convert the XYZRGBXYZRGB structure to XXYYZZRGBRGB to aid compression. For  // this, we need a vector of fields.size () (4 in this case), which points to  // each individual plane:  //   pters[0] = &only_valid_data[offset_of_plane_x];  //   pters[1] = &only_valid_data[offset_of_plane_y];  //   pters[2] = &only_valid_data[offset_of_plane_z];  //   pters[3] = &only_valid_data[offset_of_plane_RGB];  //  std::vector<char*> pters (fields.size ());  int toff = 0;  for (size_t i = 0; i < pters.size (); ++i)  {    pters[i] = &only_valid_data[toff];    toff += fields_sizes[i] * static_cast<int> (cloud.points.size ());  }    // Go over all the points, and copy the data in the appropriate places  for (size_t i = 0; i < cloud.points.size (); ++i)  {    for (size_t j = 0; j < fields.size (); ++j)    {      memcpy (pters[j], reinterpret_cast<const char*> (&cloud.points[i]) + fields[j].offset, fields_sizes[j]);      // Increment the pointer      pters[j] += fields_sizes[j];    }  }  char* temp_buf = static_cast<char*> (malloc (static_cast<size_t> (static_cast<float> (data_size) * 1.5f + 8.0f)));  // Compress the valid data  unsigned int compressed_size = pcl::lzfCompress (only_valid_data,                                                    static_cast<uint32_t> (data_size),                                                    &temp_buf[8],                                                    static_cast<uint32_t> (static_cast<float>(data_size) * 1.5f));  unsigned int compressed_final_size = 0;  // Was the compression successful?//.........这里部分代码省略.........
开发者ID:Tonsty,项目名称:pcl,代码行数:101,


示例5: main

int main (int argc, char *argv[]){  if (argc != 5) {    fputs("Usage: lab1 [enc|dec] <input file> <output file> <key>", stderr);    return -1;  }  enum mode mod;  if (strncmp(argv[1], "enc", 3) == 0) {    mod = ENC;  } else if (strncmp(argv[1], "dec", 3) == 0) {    mod = DEC;  } else {    fprintf(stderr, "Wrong encryption mode: /"%s/".", argv[1]);    return -1;  }  HANDLE inf = 0;  HANDLE inmmf = 0;  PBYTE indata = NULL;  HANDLE outf = 0;  HANDLE outmmf = 0;  PBYTE outdata = NULL;  LARGE_INTEGER insz = {.QuadPart = 0};  LARGE_INTEGER outsz = {.QuadPart = 0};  unsigned char err = 1;  inf = CreateFileA(argv[2], GENERIC_READ, 0, NULL, OPEN_EXISTING,                    FILE_ATTRIBUTE_NORMAL, NULL);  //printf("%0.16lx || %lu %s/n", inf, GetLastError(), argv[2]);  inmmf = CreateFileMappingA(inf, NULL, PAGE_READONLY, 0, 0, NULL);  if (inmmf == NULL) {    fprintf(stderr, "Can't open memory mapped file. Error code: %lu/n",            GetLastError());    goto err;  }  indata = (PBYTE)MapViewOfFile(inmmf, FILE_MAP_READ, 0, 0, 0);  if (indata == NULL) {    fprintf(stderr, "Can't map view of file. Error code: %lu/n", GetLastError());    goto err;  }  GetFileSizeEx(inf, &insz);  outsz.QuadPart = (insz.QuadPart / 8 + 2) * 8;  outf = CreateFileA(argv[3], GENERIC_READ | GENERIC_WRITE, 0, NULL,                     CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);  outmmf = CreateFileMappingA(outf, NULL, PAGE_READWRITE,                              outsz.HighPart, outsz.LowPart, NULL);  if (outmmf == NULL) {    fprintf(stderr, "Can't open memory mapped file. Error code: %lu/n",            GetLastError());    goto err;  }  outdata = (PBYTE)MapViewOfFile(outmmf, FILE_MAP_WRITE, 0, 0, 0);  if (outdata == NULL) {    fprintf(stderr, "Can't map view of file. Error code: %lu/n", GetLastError());    goto err;  }  // Crypto stuff  BOOL res;  HCRYPTPROV prov;  if (!CryptAcquireContext(&prov, 0, MS_ENHANCED_PROV, PROV_RSA_FULL,                           CRYPT_VERIFYCONTEXT)) {    fputs("Cannot acquire crypt context.", stderr);    goto err;  }  HCRYPTKEY key = generateKey(prov, CALG_3DES, argv[4]);  crash_if(key == 0, "Cannot make a key.");  for (LARGE_INTEGER i = {.QuadPart = 0}; i.QuadPart < insz.QuadPart;       (i.QuadPart) += buf_size) {    unsigned char buf[buf_size + block_size];    DWORD len = buf_size;    void *inp = indata + i.QuadPart,         *outp = outdata + i.QuadPart;    BOOL final = insz.QuadPart - i.QuadPart <= buf_size;    if (final) {      len = insz.QuadPart - i.QuadPart;    }    memcpy(buf, inp, len);    if (mod == ENC) {      res = CryptEncrypt(key, 0, final, 0, buf, &len, buf_size + block_size);    } else {      res = CryptDecrypt(key, 0, final, 0, buf, &len);    }    if (res) {      memcpy(outp, buf, len);      if (final) {        outsz.QuadPart = i.QuadPart + len;      }//.........这里部分代码省略.........
开发者ID:gekola,项目名称:BSUIR-labs,代码行数:101,


示例6: SioOpen

/*-----------------------------------------------------------------------------*  Schnittstelle 
C++ CreateFileMapping函数代码示例
C++ CreateFile函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。