Beispiel #1
0
int _tmain(int argc, _TCHAR* argv[])
{
	_tsetlocale(LC_ALL, _T("Russian"));

	int c = 0;

	while (c != 7) {

		_tprintf(_T("\n======================= Menu ==========================\n\n"));
		_tprintf(_T("1. Task1 (32bit time)\n"));
		_tprintf(_T("2. Task2 (GetSystemTimePreciseAsFileTime, GetTickCount accuracy)\n"));
		_tprintf(_T("3. Task3 (__rdtsc, QueryPerformanceCounter for array summing)\n"));
		_tprintf(_T("4. Task4 (T(200000)/T (100000), T(300000)/T (100000))\n"));
		_tprintf(_T("5. Task5.1 (matrix multiplying with class)\n"));
		_tprintf(_T("6. Task5.2 (matrix multiplying without class)\n"));
		_tprintf(_T("Print operation: "));
		_tscanf_s(_T("%d"), &c);
		

		switch (c) {
		case 1:
			_tprintf(_T("\n======================= Task 1 ==========================\n\n"));
			taskOne();
			break;
		case 2:
			_tprintf(_T("\n======================= Task 2 ==========================\n\n"));
			taskTwo();
			break;
		case 3:
			_tprintf(_T("\n======================= Task 3 ==========================\n\n"));
			taskThree();
			break;
		case 4:
			_tprintf(_T("\n======================= Task 4 ==========================\n\n"));
			taskFour();
			break;
		case 5:
			_tprintf(_T("\n======================= Task 5.1 ==========================\n\n"));
			taskFiveWithClass();
			break;
		case 6:
			_tprintf(_T("\n======================= Task 5.2 ==========================\n\n"));
			taskFiveWithoutClass();
			break;
		}
		_tprintf(_T("\n"));
	}

	return 0;
}
Beispiel #2
0
int _tmain (int argc, LPTSTR argv [])
{
    HANDLE hInFile;
    LARGE_INTEGER CurPtr;
    DWORD nRead, RecSize;
    TCHAR buffer[MAX_LINE_SIZE + 1];
    BOOL Exit = FALSE;
    LPTSTR p;
    int RecNo;

    if (argc != 2)
        ReportError (_T ("Usage: getn file"), 1, FALSE);
    hInFile = CreateFile (argv [1], GENERIC_READ,
                          0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (hInFile == INVALID_HANDLE_VALUE)
        ReportError (_T ("getn error: Cannot open file."), 2, TRUE);

    RecSize = 0;
    /* Get the record size from the first record.
    	Read the max line size and look for a CR/LF. */

    if (!ReadFile (hInFile, buffer, sizeof (buffer), &nRead, NULL) || nRead == 0)
        ReportError (_T ("Nothing to read."), 1, FALSE);
    if ((p = _tstrstr (buffer, _T ("\r\n"))) == NULL)
        ReportError (_T ("No end of line found."), 2, FALSE);
    /* Ignore Win64 warning about possible loss of data */
    RecSize = (DWORD)(p - buffer + 2);	/* 2 for the CRLF. */

    _tprintf (_T ("Record size is: %d\n"), RecSize);

    while (TRUE)
    {
        _tprintf (_T ("Enter record number. Negative to exit: "));
        _tscanf_s (_T ("%d"), &RecNo);
        if (RecNo < 0) break;

        CurPtr.QuadPart = (LONGLONG) RecNo * RecSize;
        if (!SetFilePointerEx (hInFile, CurPtr, NULL, FILE_BEGIN))
            /* Alternative: Use an overlapped structure */
            ReportError (_T ("getn Error: Set Pointer."), 3, TRUE);
        if (!ReadFile (hInFile, buffer, RecSize,  &nRead, NULL) || (nRead != RecSize))
            ReportError (_T ("Error reading n-th record."), 0, TRUE);
        buffer[RecSize] = _T('\0');
        _tprintf (_T ("%s\n"), buffer);
    }
    CloseHandle (hInFile);
    return 0;
}
Beispiel #3
0
int CServerSocket::WaitRecData(BOOL IsThread)
{
	if(IsThread == FALSE)
 		ThreadRecv(this); //普通方式运行(阻塞进程)
	else
	{
		m_hThread = CreateThread(NULL,0,ThreadRecv,this,0,0); //线程方式运行(非阻塞进程)
		TCHAR cmd[100]={0};
		do
		{
			_tscanf_s(_T("%s"),cmd);
		}
		while(_tcsicmp(_T("exit"),cmd)!=0);
	}

	return 0;
}
int _tmain(int argc, TCHAR* argv[])
{
	int a, b;

	_try
	{
		_tprintf_s(_T("input divide string [ a / b ] : "));
		//_tscanf(_T("%d %d"), &a, &b);
		_tscanf_s(_T("%d %d"), &a, &b);
		
		if (b == 0)
			return -1;
	}
	_finally
	{
		_tprintf(_T("_finally block!\n"));
	}

	_tprintf(_T("result: %d\n"), a / b);
	return 0;
}
Beispiel #5
0
int _tmain(int argc, _TCHAR* argv[])
{
	_tsetlocale(LC_ALL, _T("Russian"));
	_tprintf(_T("Сколько файлов желаете создать???:\n"));
	size_t c = -1;
	int count = 0;
	_tscanf_s(_T("%d"), &c);
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	memset(&si, 0, sizeof(STARTUPINFO));
	si.cb = sizeof(STARTUPINFO);
	SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);

	SYSTEMTIME st;
	FILETIME ft;
	GetLocalTime(&st);
	SystemTimeToFileTime(&st, &ft);
	__int64 minTime = (__int64(ft.dwHighDateTime) << 32) | __int64(ft.dwLowDateTime);
	char value[MAX_PATH];
	//*((__int64*)value) = minTime;
	_i64toa(minTime, value, 10);
	wchar_t* wString = new wchar_t[4096];
	MultiByteToWideChar(CP_ACP, 0, value, -1, wString, 4096);
	SetEnvironmentVariable(_T("NotepadTime"), wString);
	while (count < c) {
		TCHAR ProcName[] = _T("1_Notepad.exe");
		BOOL flag = CreateUnsuspendedProcess(ProcName, &si, &pi);
		WaitForSingleObject(pi.hProcess, INFINITE);
		count++;
	}
	TCHAR ProcName1[] = _T("2_FindAndGetInfo.exe");
	BOOL b = CreateUnsuspendedProcess(ProcName1, &si, &pi);
	WaitForSingleObject(pi.hProcess, INFINITE);
	CloseHandle(pi.hThread);
	CloseHandle(pi.hProcess);
	return 0;
}
Beispiel #6
0
int CommandCopy::copyFile(MyString src, MyString dst, VirtualDiskNode* vfs)
{
    HANDLE src_file = CreateFile(src.c_str(),
                                 GENERIC_READ,
                                 FILE_SHARE_READ,
                                 nullptr,
                                 OPEN_EXISTING,
                                 FILE_ATTRIBUTE_NORMAL,
                                 nullptr);
    if (src_file == INVALID_HANDLE_VALUE) 
    {
        throw CommandException(_T("系统找不到指定的文件\n"));
    }
    DWORD file_size = GetFileSize(src_file, nullptr);
    //CHAR *src_buf = new CHAR[file_size];
    DelegateMem<char> src_buf(new char[file_size]);
    DWORD read_bytes = 0;
    if (!ReadFile(src_file, 
                  src_buf,
                  file_size,
                  &read_bytes,
                  nullptr)
        || file_size != read_bytes)
    {
        //delete[] src_buf;
        CloseHandle(src_file);
        throw CommandException(src + _T("文件读取失败\n"));
    }

    FileHandler dst_file(nullptr);
    if (vfs->isFile(dst))
    {
        _tprintf(_T("覆盖文件%s,是否确认<Y/N>?"), basename(dst).c_str());
        TCHAR confirm = 0;
        _tscanf_s(_T("%c%*c"), &confirm, sizeof(confirm));
        if (confirm != 'y' && confirm != 'Y')
        {
            return 0;
        }
        dst_file = vfs->openFile(dst);
        if (!dst_file.isValid())
        {
            //delete[] src_buf;
            CloseHandle(src_file);
            throw CommandException(_T("无法打开/创建目标文件\n"));
        }
    }
    else
    {
        dst_file = vfs->createFile(dst);
        if (!dst_file.isValid())
        {
            CloseHandle(src_file);
            throw CommandException(_T("无法打开/创建目标文件\n"));
        }
    }
    // TODO : 文件写入
    dst_file.write(src_buf, file_size);
    //delete[] src_file;
    CloseHandle(src_file);
    return 0;
}