From ebea945d01f42bc92cb13fd071ade7bfb014d9cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Kri=C5=BEan?= Date: Mon, 12 Nov 2018 16:59:18 +0100 Subject: [PATCH 1/7] Solution for Day1 first exercise --- exercise/01/app/Source.cpp | 24 ++ exercise/01/app/app.vcxproj | 140 +++++++ exercise/01/app/app.vcxproj.filters | 22 + exercise/01/dll1/dynamic_library.vcxproj | 396 +++++++++--------- .../dll2/dynamic_library_with_implib.vcxproj | 342 +++++++-------- exercise/01/e01.sln | 132 +++--- exercise/01/lib/static_library.vcxproj | 336 +++++++-------- 7 files changed, 789 insertions(+), 603 deletions(-) create mode 100644 exercise/01/app/Source.cpp create mode 100644 exercise/01/app/app.vcxproj create mode 100644 exercise/01/app/app.vcxproj.filters diff --git a/exercise/01/app/Source.cpp b/exercise/01/app/Source.cpp new file mode 100644 index 0000000..5453432 --- /dev/null +++ b/exercise/01/app/Source.cpp @@ -0,0 +1,24 @@ +#include +#include "../lib/public.h" // public.h from static library +#include "../dll2/public.h" // public.h from implib dll +#include + + +int main() +{ + std::cout << "Static library: " << static_lib::get_value(1) << std::endl; + std::cout << "Dynamic library with implib: " << get_value(1) << std::endl; + const HMODULE handle = LoadLibraryA("dynamic_library.dll"); + if (0 == handle) + { + std::cout << "failed to load dll" << std::endl; + return 1; + } + + typedef double(*LPGETVALUE)(int input); + LPGETVALUE function; + function = (LPGETVALUE) GetProcAddress(handle, "get_value"); + std::cout << "Dynamic library: " << function(1) << std::endl; + FreeLibrary(handle); + return 0; +} \ No newline at end of file diff --git a/exercise/01/app/app.vcxproj b/exercise/01/app/app.vcxproj new file mode 100644 index 0000000..b68995f --- /dev/null +++ b/exercise/01/app/app.vcxproj @@ -0,0 +1,140 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {FC9C758F-B7D8-40C6-B635-41BC626509B6} + app + 10.0.17134.0 + + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + Application + true + v141 + MultiByte + + + Application + false + v141 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + Level3 + Disabled + true + true + + + $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + Console + + + + + Level3 + Disabled + true + true + + + $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + Console + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + Console + + + + + + + + + \ No newline at end of file diff --git a/exercise/01/app/app.vcxproj.filters b/exercise/01/app/app.vcxproj.filters new file mode 100644 index 0000000..4530452 --- /dev/null +++ b/exercise/01/app/app.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;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/exercise/01/dll1/dynamic_library.vcxproj b/exercise/01/dll1/dynamic_library.vcxproj index 7530308..b7e31f3 100644 --- a/exercise/01/dll1/dynamic_library.vcxproj +++ b/exercise/01/dll1/dynamic_library.vcxproj @@ -1,199 +1,199 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {92DBD108-3D52-419D-BC33-217327A4AD9D} - Win32Proj - dynamiclibrary - 10.0.17134.0 - - - - DynamicLibrary - true - v141 - Unicode - - - DynamicLibrary - false - v141 - true - Unicode - - - DynamicLibrary - true - v141 - Unicode - - - DynamicLibrary - false - v141 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - true - $(Platform)\$(Configuration)\ - - - false - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - false - $(Platform)\$(Configuration)\ - - - - Use - Level3 - Disabled - true - WIN32;_DEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - - - - - del $(TargetDir)\dynamic_library.lib - - - - - - - Use - Level3 - Disabled - true - _DEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - - - - - del $(TargetDir)\dynamic_library.lib - - - - - - - Use - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - del $(TargetDir)\dynamic_library.lib - - - - - - - Use - Level3 - MaxSpeed - true - true - true - NDEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - del $(TargetDir)\dynamic_library.lib - - - - - - - - - - - - Create - Create - Create - Create - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {92DBD108-3D52-419D-BC33-217327A4AD9D} + Win32Proj + dynamiclibrary + 10.0.17134.0 + + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + del $(TargetDir)\dynamic_library.lib + + + + + + + Use + Level3 + Disabled + true + _DEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + del $(TargetDir)\dynamic_library.lib + + + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + del $(TargetDir)\dynamic_library.lib + + + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;DYNAMICLIBRARY_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + del $(TargetDir)\dynamic_library.lib + + + + + + + + + + + + Create + Create + Create + Create + + + + + \ No newline at end of file diff --git a/exercise/01/dll2/dynamic_library_with_implib.vcxproj b/exercise/01/dll2/dynamic_library_with_implib.vcxproj index 9ad2802..ccde200 100644 --- a/exercise/01/dll2/dynamic_library_with_implib.vcxproj +++ b/exercise/01/dll2/dynamic_library_with_implib.vcxproj @@ -1,172 +1,172 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {4EA09877-C87B-489E-9F80-A921D8E66E46} - Win32Proj - dynamiclibrarywithimplib - 10.0.17134.0 - - - - DynamicLibrary - true - v141 - Unicode - - - DynamicLibrary - false - v141 - true - Unicode - - - DynamicLibrary - true - v141 - Unicode - - - DynamicLibrary - false - v141 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - true - $(Platform)\$(Configuration)\ - - - false - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - false - $(Platform)\$(Configuration)\ - - - - Use - Level3 - Disabled - true - WIN32;_DEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - - - - - Use - Level3 - Disabled - true - _DEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - - - - - Use - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - Use - Level3 - MaxSpeed - true - true - true - NDEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - - - - - - - Create - Create - Create - Create - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {4EA09877-C87B-489E-9F80-A921D8E66E46} + Win32Proj + dynamiclibrarywithimplib + 10.0.17134.0 + + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + DynamicLibrary + true + v141 + Unicode + + + DynamicLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Use + Level3 + Disabled + true + _DEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Use + Level3 + MaxSpeed + true + true + true + NDEBUG;DYNAMICLIBRARYWITHIMPLIB_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + Create + Create + Create + Create + + + + + \ No newline at end of file diff --git a/exercise/01/e01.sln b/exercise/01/e01.sln index fb6ce37..d433e0f 100644 --- a/exercise/01/e01.sln +++ b/exercise/01/e01.sln @@ -1,66 +1,66 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28010.2036 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "static_library", "lib\static_library.vcxproj", "{990D865F-0DF2-40ED-8622-8DD0DB4A2128}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "app", "app\app.vcxproj", "{843D77A9-6E04-4515-91D5-A010A5CDF8E0}" - ProjectSection(ProjectDependencies) = postProject - {92DBD108-3D52-419D-BC33-217327A4AD9D} = {92DBD108-3D52-419D-BC33-217327A4AD9D} - {990D865F-0DF2-40ED-8622-8DD0DB4A2128} = {990D865F-0DF2-40ED-8622-8DD0DB4A2128} - {4EA09877-C87B-489E-9F80-A921D8E66E46} = {4EA09877-C87B-489E-9F80-A921D8E66E46} - EndProjectSection -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamic_library", "dll1\dynamic_library.vcxproj", "{92DBD108-3D52-419D-BC33-217327A4AD9D}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamic_library_with_implib", "dll2\dynamic_library_with_implib.vcxproj", "{4EA09877-C87B-489E-9F80-A921D8E66E46}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x64.ActiveCfg = Debug|x64 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x64.Build.0 = Debug|x64 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x86.ActiveCfg = Debug|Win32 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x86.Build.0 = Debug|Win32 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x64.ActiveCfg = Release|x64 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x64.Build.0 = Release|x64 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.ActiveCfg = Release|Win32 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.Build.0 = Release|Win32 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Debug|x64.ActiveCfg = Debug|x64 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Debug|x64.Build.0 = Debug|x64 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Debug|x86.ActiveCfg = Debug|Win32 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Debug|x86.Build.0 = Debug|Win32 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Release|x64.ActiveCfg = Release|x64 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Release|x64.Build.0 = Release|x64 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Release|x86.ActiveCfg = Release|Win32 - {843D77A9-6E04-4515-91D5-A010A5CDF8E0}.Release|x86.Build.0 = Release|Win32 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x64.ActiveCfg = Debug|x64 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x64.Build.0 = Debug|x64 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x86.ActiveCfg = Debug|Win32 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x86.Build.0 = Debug|Win32 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x64.ActiveCfg = Release|x64 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x64.Build.0 = Release|x64 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.ActiveCfg = Release|Win32 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.Build.0 = Release|Win32 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x64.ActiveCfg = Debug|x64 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x64.Build.0 = Debug|x64 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x86.ActiveCfg = Debug|Win32 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x86.Build.0 = Debug|Win32 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x64.ActiveCfg = Release|x64 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x64.Build.0 = Release|x64 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.ActiveCfg = Release|Win32 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {D6B8F75A-8322-45FC-87C0-577EA4FE9944} - EndGlobalSection -EndGlobal + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2036 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "static_library", "lib\static_library.vcxproj", "{990D865F-0DF2-40ED-8622-8DD0DB4A2128}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamic_library", "dll1\dynamic_library.vcxproj", "{92DBD108-3D52-419D-BC33-217327A4AD9D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamic_library_with_implib", "dll2\dynamic_library_with_implib.vcxproj", "{4EA09877-C87B-489E-9F80-A921D8E66E46}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "app", "app\app.vcxproj", "{FC9C758F-B7D8-40C6-B635-41BC626509B6}" + ProjectSection(ProjectDependencies) = postProject + {92DBD108-3D52-419D-BC33-217327A4AD9D} = {92DBD108-3D52-419D-BC33-217327A4AD9D} + {990D865F-0DF2-40ED-8622-8DD0DB4A2128} = {990D865F-0DF2-40ED-8622-8DD0DB4A2128} + {4EA09877-C87B-489E-9F80-A921D8E66E46} = {4EA09877-C87B-489E-9F80-A921D8E66E46} + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x64.ActiveCfg = Debug|x64 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x64.Build.0 = Debug|x64 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x86.ActiveCfg = Debug|Win32 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x86.Build.0 = Debug|Win32 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x64.ActiveCfg = Release|x64 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x64.Build.0 = Release|x64 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.ActiveCfg = Debug|Win32 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.Build.0 = Debug|Win32 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x64.ActiveCfg = Debug|x64 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x64.Build.0 = Debug|x64 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x86.ActiveCfg = Debug|Win32 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x86.Build.0 = Debug|Win32 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x64.ActiveCfg = Release|x64 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x64.Build.0 = Release|x64 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.ActiveCfg = Debug|Win32 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.Build.0 = Debug|Win32 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x64.ActiveCfg = Debug|x64 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x64.Build.0 = Debug|x64 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x86.ActiveCfg = Debug|Win32 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x86.Build.0 = Debug|Win32 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x64.ActiveCfg = Release|x64 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x64.Build.0 = Release|x64 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.ActiveCfg = Debug|Win32 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.Build.0 = Debug|Win32 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x64.ActiveCfg = Debug|x64 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x64.Build.0 = Debug|x64 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x86.ActiveCfg = Debug|Win32 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x86.Build.0 = Debug|Win32 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x64.ActiveCfg = Release|x64 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x64.Build.0 = Release|x64 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x86.ActiveCfg = Debug|Win32 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x86.Build.0 = Debug|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {D6B8F75A-8322-45FC-87C0-577EA4FE9944} + EndGlobalSection +EndGlobal diff --git a/exercise/01/lib/static_library.vcxproj b/exercise/01/lib/static_library.vcxproj index 9e42fda..a31fdeb 100644 --- a/exercise/01/lib/static_library.vcxproj +++ b/exercise/01/lib/static_library.vcxproj @@ -1,169 +1,169 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128} - Win32Proj - staticlibrary - 10.0.17134.0 - - - - StaticLibrary - true - v141 - Unicode - - - StaticLibrary - false - v141 - true - Unicode - - - StaticLibrary - true - v141 - Unicode - - - StaticLibrary - false - v141 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - true - $(Platform)\$(Configuration)\ - - - false - $(Platform)\$(Configuration)\ - $(Platform)\$(Configuration)\ - - - false - $(Platform)\$(Configuration)\ - - - - NotUsing - Level3 - Disabled - true - WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) - true - - - Windows - true - - - - - NotUsing - Level3 - Disabled - true - _DEBUG;_LIB;%(PreprocessorDefinitions) - true - - - Windows - true - - - - - NotUsing - Level3 - MaxSpeed - true - true - true - WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - NotUsing - Level3 - MaxSpeed - true - true - true - NDEBUG;_LIB;%(PreprocessorDefinitions) - true - - - Windows - true - true - true - - - - - - - - NotUsing - NotUsing - NotUsing - NotUsing - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128} + Win32Proj + staticlibrary + 10.0.17134.0 + + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + true + $(SolutionDir)$(Platform)\$(Configuration)\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + false + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + NotUsing + Level3 + Disabled + true + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + NotUsing + NotUsing + NotUsing + NotUsing + + + + + \ No newline at end of file From 520d59ab9c889e252b8a022f1c1d7c60188d3d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Kri=C5=BEan?= Date: Mon, 12 Nov 2018 19:45:07 +0100 Subject: [PATCH 2/7] Reverted projects to original commit - change in output path will be replaced with prebuild step --- exercise/01/dll1/dynamic_library.vcxproj | 8 ++++---- exercise/01/dll2/dynamic_library_with_implib.vcxproj | 8 ++++---- exercise/01/lib/static_library.vcxproj | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/exercise/01/dll1/dynamic_library.vcxproj b/exercise/01/dll1/dynamic_library.vcxproj index b7e31f3..1f45ef7 100644 --- a/exercise/01/dll1/dynamic_library.vcxproj +++ b/exercise/01/dll1/dynamic_library.vcxproj @@ -72,21 +72,21 @@ true - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ true - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ false - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ false - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ diff --git a/exercise/01/dll2/dynamic_library_with_implib.vcxproj b/exercise/01/dll2/dynamic_library_with_implib.vcxproj index ccde200..574fdee 100644 --- a/exercise/01/dll2/dynamic_library_with_implib.vcxproj +++ b/exercise/01/dll2/dynamic_library_with_implib.vcxproj @@ -72,21 +72,21 @@ true - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ true - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ false - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ false - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ diff --git a/exercise/01/lib/static_library.vcxproj b/exercise/01/lib/static_library.vcxproj index a31fdeb..d1ae44b 100644 --- a/exercise/01/lib/static_library.vcxproj +++ b/exercise/01/lib/static_library.vcxproj @@ -72,21 +72,21 @@ true - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ true - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ false - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ $(Platform)\$(Configuration)\ false - $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ From def3555dbe3fd58e976893ce07fb79667b652a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Kri=C5=BEan?= Date: Mon, 12 Nov 2018 20:31:20 +0100 Subject: [PATCH 3/7] Added wrapper for function imported from dll - added RAII wrapper for LoadLibrary-FreeLibrary functions - fixed build configurations --- exercise/01/app/Source.cpp | 53 ++++++++++++++++++++++++++++++------- exercise/01/app/app.vcxproj | 42 ++++++++++++++++++++++++++--- exercise/01/e01.sln | 16 +++++------ 3 files changed, 90 insertions(+), 21 deletions(-) diff --git a/exercise/01/app/Source.cpp b/exercise/01/app/Source.cpp index 5453432..cb30a3c 100644 --- a/exercise/01/app/Source.cpp +++ b/exercise/01/app/Source.cpp @@ -2,23 +2,58 @@ #include "../lib/public.h" // public.h from static library #include "../dll2/public.h" // public.h from implib dll #include + +struct function_wrapper +{ + function_wrapper(std::string const& path, std::string const& function) + { + m_handle = LoadLibraryA(path.c_str()); + if (nullptr == m_handle) + { + throw std::invalid_argument("invalid path to target dll"); + } + m_function = (function_t) ::GetProcAddress(m_handle, function.c_str()); + if (nullptr == m_function) + { + throw std::invalid_argument("invalid function argument"); + } + } + + ~function_wrapper() + { + ::FreeLibrary(m_handle); + } + + double operator()(const int arg) const + { + return m_function(arg); + } + +private: + typedef double(*function_t)(int input); + function_t m_function; + HMODULE m_handle; +}; + +namespace dynamic_lib +{ + const function_wrapper get_value("dynamic_library.dll", "get_value"); +} int main() { std::cout << "Static library: " << static_lib::get_value(1) << std::endl; - std::cout << "Dynamic library with implib: " << get_value(1) << std::endl; - const HMODULE handle = LoadLibraryA("dynamic_library.dll"); - if (0 == handle) + try + { + std::cout << "Dynamic library without implib: " << dynamic_lib::get_value(1) << std::endl; + } + catch (std::invalid_argument& e) { - std::cout << "failed to load dll" << std::endl; + std::cout << e.what() << std::endl; return 1; } + std::cout << "Dynamic library with implib: " << get_value(1) << std::endl; - typedef double(*LPGETVALUE)(int input); - LPGETVALUE function; - function = (LPGETVALUE) GetProcAddress(handle, "get_value"); - std::cout << "Dynamic library: " << function(1) << std::endl; - FreeLibrary(handle); return 0; } \ No newline at end of file diff --git a/exercise/01/app/app.vcxproj b/exercise/01/app/app.vcxproj index b68995f..dbb4f4e 100644 --- a/exercise/01/app/app.vcxproj +++ b/exercise/01/app/app.vcxproj @@ -71,9 +71,11 @@ $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ @@ -83,9 +85,17 @@ true - $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + $(SolutionDir)\lib\$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) Console + + + + + + copy ..\dll1\$(Platform)\$(Configuration)\dynamic_library.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library.dll +copy ..\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.dll + @@ -95,9 +105,17 @@ true - $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + $(SolutionDir)\lib\$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) Console + + + + + + copy ..\dll1\$(Platform)\$(Configuration)\dynamic_library.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library.dll +copy ..\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.dll + @@ -111,9 +129,17 @@ true true - $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + $(SolutionDir)\lib\$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) Console + + + + + + copy ..\dll1\$(Platform)\$(Configuration)\dynamic_library.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library.dll +copy ..\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.dll + @@ -127,9 +153,17 @@ true true - $(SolutionDir)$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) + $(SolutionDir)\lib\$(Platform)\$(Configuration)\static_library.lib;$(SolutionDir)\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.lib;%(AdditionalDependencies) Console + + + + + + copy ..\dll1\$(Platform)\$(Configuration)\dynamic_library.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library.dll +copy ..\dll2\$(Platform)\$(Configuration)\dynamic_library_with_implib.dll $(SolutionDir)$(Platform)\$(Configuration)\dynamic_library_with_implib.dll + diff --git a/exercise/01/e01.sln b/exercise/01/e01.sln index d433e0f..25e735e 100644 --- a/exercise/01/e01.sln +++ b/exercise/01/e01.sln @@ -30,32 +30,32 @@ Global {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Debug|x86.Build.0 = Debug|Win32 {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x64.ActiveCfg = Release|x64 {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x64.Build.0 = Release|x64 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.ActiveCfg = Debug|Win32 - {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.Build.0 = Debug|Win32 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.ActiveCfg = Release|Win32 + {990D865F-0DF2-40ED-8622-8DD0DB4A2128}.Release|x86.Build.0 = Release|Win32 {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x64.ActiveCfg = Debug|x64 {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x64.Build.0 = Debug|x64 {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x86.ActiveCfg = Debug|Win32 {92DBD108-3D52-419D-BC33-217327A4AD9D}.Debug|x86.Build.0 = Debug|Win32 {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x64.ActiveCfg = Release|x64 {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x64.Build.0 = Release|x64 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.ActiveCfg = Debug|Win32 - {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.Build.0 = Debug|Win32 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.ActiveCfg = Release|Win32 + {92DBD108-3D52-419D-BC33-217327A4AD9D}.Release|x86.Build.0 = Release|Win32 {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x64.ActiveCfg = Debug|x64 {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x64.Build.0 = Debug|x64 {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x86.ActiveCfg = Debug|Win32 {4EA09877-C87B-489E-9F80-A921D8E66E46}.Debug|x86.Build.0 = Debug|Win32 {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x64.ActiveCfg = Release|x64 {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x64.Build.0 = Release|x64 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.ActiveCfg = Debug|Win32 - {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.Build.0 = Debug|Win32 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.ActiveCfg = Release|Win32 + {4EA09877-C87B-489E-9F80-A921D8E66E46}.Release|x86.Build.0 = Release|Win32 {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x64.ActiveCfg = Debug|x64 {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x64.Build.0 = Debug|x64 {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x86.ActiveCfg = Debug|Win32 {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Debug|x86.Build.0 = Debug|Win32 {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x64.ActiveCfg = Release|x64 {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x64.Build.0 = Release|x64 - {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x86.ActiveCfg = Debug|Win32 - {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x86.Build.0 = Debug|Win32 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x86.ActiveCfg = Release|Win32 + {FC9C758F-B7D8-40C6-B635-41BC626509B6}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From e63574227475ecf8e16104c7c1748ef9e88506d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Kri=C5=BEan?= Date: Mon, 12 Nov 2018 20:40:24 +0100 Subject: [PATCH 4/7] Removed redundant try-catch block --- exercise/01/app/Source.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/exercise/01/app/Source.cpp b/exercise/01/app/Source.cpp index cb30a3c..9547e07 100644 --- a/exercise/01/app/Source.cpp +++ b/exercise/01/app/Source.cpp @@ -44,15 +44,7 @@ namespace dynamic_lib int main() { std::cout << "Static library: " << static_lib::get_value(1) << std::endl; - try - { - std::cout << "Dynamic library without implib: " << dynamic_lib::get_value(1) << std::endl; - } - catch (std::invalid_argument& e) - { - std::cout << e.what() << std::endl; - return 1; - } + std::cout << "Dynamic library without implib: " << dynamic_lib::get_value(1) << std::endl; std::cout << "Dynamic library with implib: " << get_value(1) << std::endl; return 0; From f5cb42d47f9c33f16ab8f3db1f577f8934b2d5c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Kri=C5=BEan?= Date: Tue, 13 Nov 2018 10:28:20 +0100 Subject: [PATCH 5/7] Switched C-style cast to reinterpret_cast --- exercise/01/app/Source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercise/01/app/Source.cpp b/exercise/01/app/Source.cpp index 9547e07..35eee68 100644 --- a/exercise/01/app/Source.cpp +++ b/exercise/01/app/Source.cpp @@ -12,7 +12,7 @@ struct function_wrapper { throw std::invalid_argument("invalid path to target dll"); } - m_function = (function_t) ::GetProcAddress(m_handle, function.c_str()); + m_function = reinterpret_cast(::GetProcAddress(m_handle, function.c_str())); if (nullptr == m_function) { throw std::invalid_argument("invalid function argument"); From 30d55c6865fb3a4d77ed57355c9da86692ded876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Kri=C5=BEan?= Date: Tue, 13 Nov 2018 11:05:03 +0100 Subject: [PATCH 6/7] Finished second exercise --- exercise/02/code.cpp | 15 +++++++++++++++ exercise/02/code.h | 5 +++++ exercise/02/simple_test.sln | 31 +++++++++++++++++++++++++++++++ exercise/02/test1.cpp | 14 +++++++++++--- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 exercise/02/simple_test.sln diff --git a/exercise/02/code.cpp b/exercise/02/code.cpp index 85e778c..dedde37 100644 --- a/exercise/02/code.cpp +++ b/exercise/02/code.cpp @@ -1,2 +1,17 @@ #include "stdafx.h" #include "code.h" + +void f1(int& a, int& b) +{ + using std::swap; + swap(a, b); +} + +void f2(int* begin, int* end) +{ + while (begin < end) + { + ++(*begin); + ++begin; + } +} diff --git a/exercise/02/code.h b/exercise/02/code.h index e69de29..f95c66e 100644 --- a/exercise/02/code.h +++ b/exercise/02/code.h @@ -0,0 +1,5 @@ +#pragma once + +void f1(int& a, int& b); + +void f2(int *begin, int *end); \ No newline at end of file diff --git a/exercise/02/simple_test.sln b/exercise/02/simple_test.sln new file mode 100644 index 0000000..6ebd391 --- /dev/null +++ b/exercise/02/simple_test.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28010.2046 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "simple_test", "simple_test.vcxproj", "{F2F0B29D-E5BA-47BD-A20C-6373652373DB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Debug|x64.ActiveCfg = Debug|x64 + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Debug|x64.Build.0 = Debug|x64 + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Debug|x86.ActiveCfg = Debug|Win32 + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Debug|x86.Build.0 = Debug|Win32 + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Release|x64.ActiveCfg = Release|x64 + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Release|x64.Build.0 = Release|x64 + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Release|x86.ActiveCfg = Release|Win32 + {F2F0B29D-E5BA-47BD-A20C-6373652373DB}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {653B76CD-F447-428A-8513-2420071444A5} + EndGlobalSection +EndGlobal diff --git a/exercise/02/test1.cpp b/exercise/02/test1.cpp index 33dfab7..ff3c0e7 100644 --- a/exercise/02/test1.cpp +++ b/exercise/02/test1.cpp @@ -14,14 +14,22 @@ namespace simple_test TEST_METHOD(f1_changes_values) { int a=1, b=2; - //f1(a, b); + f1(a, b); Assert::AreEqual(2, a); Assert::AreEqual(1, b); } + + TEST_METHOD(f1_actually_swaps_value) + { + int a = 42, b = 100; + f1(a, b); + Assert::AreEqual(100, a); + Assert::AreEqual(42, b); + } TEST_METHOD(f2_increases_all_values_by_one) { int arr[] = { 1, 2, 3 }; - //f2(arr, arr+3); + f2(arr, arr+3); Assert::AreEqual(2, arr[0]); Assert::AreEqual(3, arr[1]); Assert::AreEqual(4, arr[2]); @@ -29,7 +37,7 @@ namespace simple_test TEST_METHOD(f2_works_for_different_number_of_values) { int arr[] = { 2, 4, 6, 8, 10 }; - //f2(arr, arr+5); + f2(arr, arr+5); Assert::AreEqual(3, arr[0]); Assert::AreEqual(5, arr[1]); Assert::AreEqual(7, arr[2]); From 4716e53725011aea6da3995636e8dce4ec248b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Kri=C5=BEan?= Date: Tue, 13 Nov 2018 11:18:32 +0100 Subject: [PATCH 7/7] Switched while loop to std::for_each --- exercise/02/code.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/exercise/02/code.cpp b/exercise/02/code.cpp index dedde37..335485b 100644 --- a/exercise/02/code.cpp +++ b/exercise/02/code.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" #include "code.h" +#include void f1(int& a, int& b) { @@ -9,9 +10,5 @@ void f1(int& a, int& b) void f2(int* begin, int* end) { - while (begin < end) - { - ++(*begin); - ++begin; - } + std::for_each(begin, end, [](auto& arg) {return ++arg; }); }