diff --git a/cp/Debug/test.txt b/cp/Debug/test.txt deleted file mode 100644 index 7cb95e5..0000000 --- a/cp/Debug/test.txt +++ /dev/null @@ -1 +0,0 @@ -this is a test1234 \ No newline at end of file diff --git a/cp/Debug/test2.txt b/cp/Debug/test2.txt deleted file mode 100644 index 7cb95e5..0000000 --- a/cp/Debug/test2.txt +++ /dev/null @@ -1 +0,0 @@ -this is a test1234 \ No newline at end of file diff --git a/cp/buid.sh b/cp/buid.sh new file mode 100644 index 0000000..21798a7 --- /dev/null +++ b/cp/buid.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +gcc -o main main.cpp +./main test.txt test2.txt \ No newline at end of file diff --git a/cp/build.bat b/cp/build.bat new file mode 100644 index 0000000..828633c --- /dev/null +++ b/cp/build.bat @@ -0,0 +1,3 @@ +call ../vcppbuild.bat main +move main.exe cp.exe +cp test.txt test2.txt \ No newline at end of file diff --git a/cp/cp.sln b/cp/cp.sln deleted file mode 100644 index 4b0c2f5..0000000 --- a/cp/cp.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cp", "cp\cp.vcxproj", "{520F9999-A81C-4EA3-8B7D-5074C97F584C}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {520F9999-A81C-4EA3-8B7D-5074C97F584C}.Debug|Win32.ActiveCfg = Debug|Win32 - {520F9999-A81C-4EA3-8B7D-5074C97F584C}.Debug|Win32.Build.0 = Debug|Win32 - {520F9999-A81C-4EA3-8B7D-5074C97F584C}.Release|Win32.ActiveCfg = Release|Win32 - {520F9999-A81C-4EA3-8B7D-5074C97F584C}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/cp/cp/cp.vcxproj b/cp/cp/cp.vcxproj deleted file mode 100644 index 2385ff4..0000000 --- a/cp/cp/cp.vcxproj +++ /dev/null @@ -1,82 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {520F9999-A81C-4EA3-8B7D-5074C97F584C} - Win32Proj - cp - - - - Application - true - Unicode - - - Application - false - true - Unicode - - - - - - - - - - - - - true - - - false - - - - - - Level3 - Disabled - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - - - - - Level3 - - - MaxSpeed - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/cp/cp/cp.vcxproj.filters b/cp/cp/cp.vcxproj.filters deleted file mode 100644 index 2a14256..0000000 --- a/cp/cp/cp.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Source Files - - - \ No newline at end of file diff --git a/cp/cp/main.cpp b/cp/cp/main.cpp deleted file mode 100644 index a651ac0..0000000 --- a/cp/cp/main.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include - -void WriteStr(const char * str) -{ - // A simple wrapper to output text using WriteFile - HANDLE stdout2 = GetStdHandle(STD_OUTPUT_HANDLE); - DWORD byteswritten; - int length = 0; - const char * cpyptr = str; - while(*cpyptr++) // This doesn't work the way you would expect it - length++; - WriteFile(stdout2, str, length, &byteswritten, NULL); -} - -class FileWrapper -{ -private: - HANDLE _handle; - -public: - FileWrapper(const char * file, DWORD access, DWORD creation) { this->_handle = CreateFileA(file, access, 0, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL); } - ~FileWrapper() { CloseHandle(this->_handle); } // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx - HANDLE getHandle() { return this->_handle; } -}; - -int main(int argc, char * args[]) -{ - // Parameter checking - if (argc != 3) - { - WriteStr("Please enter two parameters - cp src dst"); - return 0; - } - - // Open the source - // A little RAII - FileWrapper src(args[1], GENERIC_READ, OPEN_EXISTING); - if (GetLastError() == ERROR_FILE_NOT_FOUND) - { - WriteStr("Could not find file!"); - return 0; - } - - // Open destination file - FileWrapper dst(args[2], GENERIC_WRITE, CREATE_ALWAYS); - - DWORD numberofbytesread; - DWORD numberofbyteswritten; - char buffer[20]; - - // Stream the file instead of reading it into memory - while(true) - { - // The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array - // http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx - ReadFile(src.getHandle(), buffer, 20, &numberofbytesread, NULL); // http://stackoverflow.com/questions/12655120/readfile-function-from-win32-api - if (numberofbytesread == 0) - break; - WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL); - } - - return 0; -} \ No newline at end of file diff --git a/cp/main.cpp b/cp/main.cpp new file mode 100644 index 0000000..a651ac0 --- /dev/null +++ b/cp/main.cpp @@ -0,0 +1,63 @@ +#include + +void WriteStr(const char * str) +{ + // A simple wrapper to output text using WriteFile + HANDLE stdout2 = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD byteswritten; + int length = 0; + const char * cpyptr = str; + while(*cpyptr++) // This doesn't work the way you would expect it + length++; + WriteFile(stdout2, str, length, &byteswritten, NULL); +} + +class FileWrapper +{ +private: + HANDLE _handle; + +public: + FileWrapper(const char * file, DWORD access, DWORD creation) { this->_handle = CreateFileA(file, access, 0, NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL); } + ~FileWrapper() { CloseHandle(this->_handle); } // http://msdn.microsoft.com/en-us/library/windows/desktop/ms724211(v=vs.85).aspx + HANDLE getHandle() { return this->_handle; } +}; + +int main(int argc, char * args[]) +{ + // Parameter checking + if (argc != 3) + { + WriteStr("Please enter two parameters - cp src dst"); + return 0; + } + + // Open the source + // A little RAII + FileWrapper src(args[1], GENERIC_READ, OPEN_EXISTING); + if (GetLastError() == ERROR_FILE_NOT_FOUND) + { + WriteStr("Could not find file!"); + return 0; + } + + // Open destination file + FileWrapper dst(args[2], GENERIC_WRITE, CREATE_ALWAYS); + + DWORD numberofbytesread; + DWORD numberofbyteswritten; + char buffer[20]; + + // Stream the file instead of reading it into memory + while(true) + { + // The buffer parameter is a void pointer which means it can take anything - in this case we just use a char array + // http://msdn.microsoft.com/en-us/library/windows/desktop/aa365467(v=vs.85).aspx + ReadFile(src.getHandle(), buffer, 20, &numberofbytesread, NULL); // http://stackoverflow.com/questions/12655120/readfile-function-from-win32-api + if (numberofbytesread == 0) + break; + WriteFile(dst.getHandle(), buffer, numberofbytesread, &numberofbyteswritten, NULL); + } + + return 0; +} \ No newline at end of file diff --git a/cp/test.txt b/cp/test.txt new file mode 100644 index 0000000..496a451 --- /dev/null +++ b/cp/test.txt @@ -0,0 +1 @@ +THIS IS ONLY A TEST \ No newline at end of file diff --git a/thread-windows/build.bat b/thread-windows/build.bat new file mode 100644 index 0000000..4558362 --- /dev/null +++ b/thread-windows/build.bat @@ -0,0 +1 @@ +../vcbuild.bat main \ No newline at end of file diff --git a/thread-windows/main.c b/thread-windows/main.c new file mode 100644 index 0000000..7fc864c --- /dev/null +++ b/thread-windows/main.c @@ -0,0 +1,17 @@ +#include +#include + +DWORD WINAPI ThreadFunc(void* data) { + int i; + for(i = 0; i < 10; i++) + printf("%i\n", i); + return 0; +} + +int main() { + HANDLE thread1, thread2; + thread1 = CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL); + thread2 = CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL); + WaitForSingleObject(thread1, INFINITE); + WaitForSingleObject(thread2, INFINITE); +} \ No newline at end of file