commit bdad85c1151b75a615d13f6f22c3cf1a3cb23b03 Author: LoXur-ux Date: Thu Nov 23 15:10:31 2023 +0300 Lab 3 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0a2413b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +x86/ +x64/ +Debug +.vs \ No newline at end of file diff --git a/Project1/Project1.vcxproj b/Project1/Project1.vcxproj new file mode 100644 index 0000000..32c12ee --- /dev/null +++ b/Project1/Project1.vcxproj @@ -0,0 +1,141 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {03725c01-c78a-4b04-82ba-b2904edb050d} + Project1 + 10.0 + Console + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + {06b7759e-7c98-4da2-b1f6-78bc602b542e} + + + + + + \ No newline at end of file diff --git a/Project1/Project1.vcxproj.filters b/Project1/Project1.vcxproj.filters new file mode 100644 index 0000000..e8deb3d --- /dev/null +++ b/Project1/Project1.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;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 + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/Project1/Project1.vcxproj.user b/Project1/Project1.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/Project1/Project1.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Project1/main.cpp b/Project1/main.cpp new file mode 100644 index 0000000..31bf9dc --- /dev/null +++ b/Project1/main.cpp @@ -0,0 +1,36 @@ +#include +#include +#include "../dynamicLib/Header.h" + +using namespace std; + +int main() { + /*HINSTANCE load; + load = LoadLibrary(L"dynamicLib.dll"); + + typedef int (*pow) (int, int); + pow Pow; + + Pow = (pow)GetProcAddress(load, "Pow"); + int a, b; + + cout<<"Keep 2 numbers that you want to power: "; + cin >> a; + cin >> b; + cout << "Pow: "; + cout << Pow(a, b) << endl; + + cout << "a > b: " ; + cout << Compare(a, b);*/ + + + SpeedConverter(100, "kmh"); + SpeedConverter(60, "mph"); + + FindSmallestFileInFolder(); + + + //FreeLibrary(load); + + return 0; +} \ No newline at end of file diff --git a/dynamicLib/Header.h b/dynamicLib/Header.h new file mode 100644 index 0000000..1ad4df7 --- /dev/null +++ b/dynamicLib/Header.h @@ -0,0 +1,5 @@ +#pragma once +extern "C" __declspec(dllexport) int Pow(int, int); +extern "C" __declspec(dllexport) bool Compare(int, int); +extern "C" __declspec(dllexport) double SpeedConverter(double, std::string); +extern "C" __declspec(dllexport) wstring FindSmallestFileInFolder(); \ No newline at end of file diff --git a/dynamicLib/dynamicLib.sln b/dynamicLib/dynamicLib.sln new file mode 100644 index 0000000..e78fb42 --- /dev/null +++ b/dynamicLib/dynamicLib.sln @@ -0,0 +1,41 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34031.279 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dynamicLib", "dynamicLib.vcxproj", "{06B7759E-7C98-4DA2-B1F6-78BC602B542E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Project1", "..\Project1\Project1.vcxproj", "{03725C01-C78A-4B04-82BA-B2904EDB050D}" +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 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Debug|x64.ActiveCfg = Debug|x64 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Debug|x64.Build.0 = Debug|x64 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Debug|x86.ActiveCfg = Debug|Win32 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Debug|x86.Build.0 = Debug|Win32 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Release|x64.ActiveCfg = Release|x64 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Release|x64.Build.0 = Release|x64 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Release|x86.ActiveCfg = Release|Win32 + {06B7759E-7C98-4DA2-B1F6-78BC602B542E}.Release|x86.Build.0 = Release|Win32 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Debug|x64.ActiveCfg = Debug|x64 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Debug|x64.Build.0 = Debug|x64 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Debug|x86.ActiveCfg = Debug|Win32 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Debug|x86.Build.0 = Debug|Win32 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Release|x64.ActiveCfg = Release|x64 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Release|x64.Build.0 = Release|x64 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Release|x86.ActiveCfg = Release|Win32 + {03725C01-C78A-4B04-82BA-B2904EDB050D}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {50F1A307-DA19-4616-A96E-F36C77B3B5C4} + EndGlobalSection +EndGlobal diff --git a/dynamicLib/dynamicLib.vcxproj b/dynamicLib/dynamicLib.vcxproj new file mode 100644 index 0000000..e5997df --- /dev/null +++ b/dynamicLib/dynamicLib.vcxproj @@ -0,0 +1,138 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {06b7759e-7c98-4da2-b1f6-78bc602b542e} + dynamicLib + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/dynamicLib/dynamicLib.vcxproj.filters b/dynamicLib/dynamicLib.vcxproj.filters new file mode 100644 index 0000000..dfbd3da --- /dev/null +++ b/dynamicLib/dynamicLib.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;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 + + + + + Исходные файлы + + + + + Файлы заголовков + + + \ No newline at end of file diff --git a/dynamicLib/dynamicLib.vcxproj.user b/dynamicLib/dynamicLib.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/dynamicLib/dynamicLib.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/dynamicLib/mylibcpp.cpp b/dynamicLib/mylibcpp.cpp new file mode 100644 index 0000000..9bc2264 --- /dev/null +++ b/dynamicLib/mylibcpp.cpp @@ -0,0 +1,74 @@ +#include +#include +#include +#include + +using namespace std; + +extern "C" +__declspec(dllexport) int Pow(int num, int exp) { + for (int i = 1; i < exp; i++) + num *= num; + + return num; +} + +extern "C" +__declspec(dllexport) bool Compare(int a, int b) { + return a > b; +} + +extern "C" +__declspec(dllexport) double SpeedConverter(double speed, string unit) { + if (unit == "kmh") { + cout << "Speed in Mile: " << speed * 0.621371 << endl; + return speed * 0.621371; + } + else if (unit == "mph") { + cout << "Speed in Km: " << speed * 1.60934 << endl; + return speed * 1.60934; + } + else { + cout << "Error speed Type! Unit: kmh or mph!" << endl; + return -1; + } +} + +extern "C" +__declspec(dllexport) wstring FindSmallestFileInFolder() { + wstring folderPath; + wcout << L" : "; + wcin >> folderPath; + + + + WIN32_FIND_DATA findFileData; + HANDLE hFind = FindFirstFile((folderPath + L"\\*").c_str(), &findFileData); + wstring smallestFilePath; + uintmax_t smallestSize = numeric_limits::max(); + + if (hFind != INVALID_HANDLE_VALUE) { + do { + if ((findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { + wstring filePath = folderPath + L"\\" + findFileData.cFileName; + uintmax_t fileSize = findFileData.nFileSizeLow; + + if (fileSize < smallestSize) { + smallestSize = fileSize; + smallestFilePath = filePath; + } + } + } while (FindNextFile(hFind, &findFileData) != 0); + + FindClose(hFind); + } + + if (!smallestFilePath.empty()) { + wcout << L" : " << smallestFilePath << endl; + } + else { + wcout << L" " << endl; + } + + return smallestFilePath; +}