PanishevLab3/dynamicLib/mylibcpp.cpp
2023-11-23 15:10:31 +03:00

75 lines
1.6 KiB
C++

#include <iostream>
#include <windows.h>
#include <string>
#include <filesystem>
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<uintmax_t>::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;
}