Labs_Shishkina_Marina_ITb-4301/Main/Main.cpp
2024-12-26 15:23:34 +03:00

78 lines
2.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <iostream>
#include "Lib_Stat.h"
#include <iostream>
#include <windows.h>
#include "Lib_Dinamic.h" // Заголовочный файл с объявлениями функций
typedef void(*StartKeyLoggingFunc)();
typedef void(*StopKeyLoggingFunc)();
typedef const char* (*GetLastTenKeysFunc)();
int main() {
unsigned int n;
std::cout << "Enter the Fibonacci number: ";
std::cin >> n;
unsigned long long result = Fibonacci(n);
std::cout << n << "-e Fibonacci number: " << result << std::endl;
// Загрузить библиотеку
HMODULE hLib = LoadLibrary(TEXT("Lib_Dinamic.dll"));
if (hLib == NULL) {
std::cerr << "Failed to load library." << std::endl;
return 1;
}
// Получить адреса функций
StartKeyLoggingFunc StartKeyLogging = (StartKeyLoggingFunc)GetProcAddress(hLib, "StartKeyLogging");
StopKeyLoggingFunc StopKeyLogging = (StopKeyLoggingFunc)GetProcAddress(hLib, "StopKeyLogging");
GetLastTenKeysFunc GetLastTenKeys = (GetLastTenKeysFunc)GetProcAddress(hLib, "GetLastTenKeys");
if (!StartKeyLogging || !StopKeyLogging || !GetLastTenKeys) {
std::cerr << "Failed to get function addresses." << std::endl;
FreeLibrary(hLib);
return 1;
}
// Запустить логирование клавиш
StartKeyLogging();
std::cout << "Key logging started. Press some keys...." << std::endl;
// Подождать некоторое время, чтобы дать возможность пользователю нажать клавиши
Sleep(10000); // Ждать 10 секунд
// Остановить логирование клавиш
StopKeyLogging();
std::cout << "Key logging stopped." << std::endl;
// Спросить пользователя, хочет ли он вывести данные
std::cout << "Do you want to display data?? (y/n): ";
char answer;
std::cin >> answer;
if (answer == 'y' || answer == 'Y') {
// Получить последние 10 нажатых клавиш
const char* keys = GetLastTenKeys();
std::cout << "Last 10 keys pressed: " << keys << std::endl;
}
// Освободить библиотеку
FreeLibrary(hLib);
return 0;
}