当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 <windows.h>
#include <tchar.h>
#include <stdio.h>
#include
#include
#include <stdio.h>
#include <tlhelp32.h>
#include
#include
#include
#include
#include
#include
#include
#include
#include <windows.h>
#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_));

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);

}

// 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);

}

// 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);
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值