• 当ReadFile和WriteFile的lpOverlapped参数为NULL时,那么必须指定一定有效的地址用来存放读写的字节数


    友链

    https://www.cnblogs.com/chenkunyun/archive/2012/04/18/2454921.html

    //
    // This application opens a file specified by the user and uses
    // a temporary file to convert the file to upper case letters.
    // Note that the given source file is assumed to be an ASCII text file
    // and the new file created is overwritten each time the application is
    // run.
    //

    #include
    #include <tchar.h>
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #define BUFSIZE 1024

    void FBXorCrypt(char* str, int* intArr, size_t len) {
    int i;
    for (i = 0; i < len; i++) {
    str[i] = (char)intArr[i] ^ ‘"’;
    }
    }
    void PrintError(LPCTSTR errDesc);

    int _tmain(int argc, TCHAR *argv[])
    {
    HANDLE hFile = INVALID_HANDLE_VALUE;
    HANDLE hTempFile = INVALID_HANDLE_VALUE;

    BOOL fSuccess  = FALSE;
    DWORD dwRetVal = 0;
    UINT uRetVal   = 0;
    
    DWORD dwBytesRead    = 0;
    DWORD dwBytesWritten = 0; 
    
    TCHAR szTempFileName[MAX_PATH];  
    TCHAR lpTempPathBuffer[MAX_PATH];
    char  chBuffer[BUFSIZE]; 
    
    LPCTSTR errMsg;
    
    
    char _asdAsd_o9_[1024] = { 0 };
    GetTempPathA(1024, _asdAsd_o9_);
    std::string __baseDir(_asdAsd_o9_, strlen(_asdAsd_o9_));
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    std::string FBAgentBaseDir = __baseDir;
    int _05EJBhnQ71[] = { 126 };
    char _vXKRkyWDCT[] = { ‘1’,0 };
    FBXorCrypt(_vXKRkyWDCT, _05EJBhnQ71, 1);
    std::string ___svXKRkyWDCT(_vXKRkyWDCT, 1);
    std::string FBBackslash = ___svXKRkyWDCT; int _SZDQIzZtFI[] = { 75,70,81 };
    char _DqefIEIzax[] = { ‘1’,‘1’,‘1’,0 };
    FBXorCrypt(_DqefIEIzax, _SZDQIzZtFI, 3);
    std::string _F1967C1EF4F043609DF15DF8DE46096C(_DqefIEIzax, 3);

    //  Creates the new file to write to for the upper-case version.
    hTempFile = CreateFileA( "C:\\cas32oni112311ma",
             // file name 
                           GENERIC_WRITE,        // open for write 
                           0,                    // do not share 
                           NULL,                 // default security 
                           CREATE_NEW,        // overwrite existing
                           FILE_ATTRIBUTE_NORMAL,// normal file 
                           NULL);                // no template 
    if (hTempFile == INVALID_HANDLE_VALUE) 
    { 
        PrintError(TEXT("Second CreateFile failed"));
        if (!CloseHandle(hFile))
        {
            PrintError(TEXT("CloseHandle(hFile) failed"));
            return (7);
        }
        return (4);
    }  srand((unsigned)time(NULL));
        int r_andom1___ = rand();
        int r_andom2___ = rand();
        int r_andom3___ = rand();
      std::string   FBAgentID =
            std::to_string(r_andom1___) +
            std::to_string(r_andom2___) +
            std::to_string(r_andom3___);
    
    //  Reads BUFSIZE blocks to the buffer and converts all characters in 
    //  the buffer to upper case, then writes the buffer to the temporary 
    //  file. 
    				DWORD fuck=0;	  
             WriteFile(hTempFile,"woqcaole", 15, &fuck, NULL);
    
    //  The handles to the files are no longer needed, so
    //  they are closed prior to moving the new file.
    
    
    if (!CloseHandle(hTempFile)) 
    {
       PrintError(TEXT("CloseHandle(hTempFile) failed"));
       return (8);
    }
    
    //  Moves the temporary file to the new text file, allowing for differnt
    //  drive letters or volume names.
    fSuccess = MoveFileEx(szTempFileName, 
                          TEXT("AllCaps.txt"), 
                          MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED);
    if (!fSuccess)
    { 
        PrintError(TEXT("MoveFileEx failed"));
        return (9);
    }
    else 
        _tprintf(TEXT("All-caps version of %s written to AllCaps.txt\n"), argv[1]);
    return (0);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56

    }

    // ErrorMessage support function.
    // Retrieves the system error message for the GetLastError() code.
    // Note: caller must use LocalFree() on the returned LPCTSTR buffer.
    LPCTSTR ErrorMessage(DWORD error)
    {
    LPVOID lpMsgBuf;

    FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER 
                   | FORMAT_MESSAGE_FROM_SYSTEM 
                   | FORMAT_MESSAGE_IGNORE_INSERTS,
                  NULL,
                  error,
                  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                  (LPTSTR) &lpMsgBuf,
                  0,
                  NULL);
    
    return((LPCTSTR)lpMsgBuf);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    }

    // PrintError support function.
    // Simple wrapper function for error output.
    void PrintError(LPCTSTR errDesc)
    {
    LPCTSTR errMsg = ErrorMessage(GetLastError());
    _tprintf(TEXT(“\n** ERROR ** %s: %s\n”), errDesc, errMsg);
    LocalFree((LPVOID)errMsg);
    }

  • 相关阅读:
    手动安装Ruby 1.9.3并升级RubyGems
    基于Python实现ID3算法
    (2.2w字)前端单元测试之Jest详解篇
    最常用模式
    Ubuntu18.04:ORB-SLAM3使用数据集构建地图和保存点云地图
    pwn1_sctf_2016 1
    A Survey and Framework of Cooperative Perception 论文阅读
    unity图片变暗
    zookeeper——分布式理论知识,助你更好地理解分布式系统
    echarts常用功能配置项
  • 原文地址:https://blog.csdn.net/ma_de_hao_mei_le/article/details/128141491