
#include <Windows.h>
#include <iostream>
#include <tchar.h>
int main()
{
auto IsFileExist = [](const char* szFileExist) -> bool {
return (GetFileAttributes(szFileExist) != INVALID_FILE_ATTRIBUTES);
};
const char* szCurFileNames[] = {
_T("CShell_x64.dll"),
_T("Object_x64.dll")
};
int is_selected = 0;
std::cout << _T("Select a DLL to load:") << std::endl;
for (int i = 0; i < sizeof(szCurFileNames) / sizeof(szCurFileNames[0]); ++i) {
std::cout << i + 1 << ". " << szCurFileNames[i] << std::endl;
}
std::cout << sizeof(szCurFileNames) / sizeof(szCurFileNames[0]) + 1 << _T(". Load a custom DLL") << std::endl;
std::cout << _T("Select the the right number you want to load ^_^: ");
std::cin >> is_selected;
if (is_selected >= 1 && is_selected <= sizeof(szCurFileNames) / sizeof(szCurFileNames[0]) + 1)
{
if (is_selected <= sizeof(szCurFileNames) / sizeof(szCurFileNames[0]))
{
const char* szFileName = szCurFileNames[is_selected - 1];
if (IsFileExist(szFileName))
{
auto hModule = LoadLibrary(szFileName);
if (hModule != NULL) {
std::cout << _T("Module ") << szFileName << _T(" has been loaded!") << std::endl;
}
else {
std::cout << _T("Failed to load the module ") << szFileName << _T(", Error: 0x") << std::hex << GetLastError() << std::dec << "." << std::endl;
}
}
else {
std::cout << _T("Failed! File ") << szFileName << _T(" does not exist, Error: 0x") << std::hex << GetLastError() << std::dec << "." << std::endl;
}
}
else {
std::string szCustomFileName;
std::cout << _T("Enter the name of the custom DLL: ");
std::cin >> szCustomFileName;
if (IsFileExist(szCustomFileName.c_str()))
{
auto hModule = LoadLibrary(szCustomFileName.c_str());
if (hModule != NULL) {
std::cout << _T("Custom DLL ") << szCustomFileName << _T(" has been loaded!") << std::endl;
}
else {
std::cout << _T("Failed to load the custom DLL ") << szCustomFileName << _T(", Error: 0x") << std::hex << GetLastError() << std::dec << "." << std::endl;
}
}
else {
std::cout << _T("Failed! File ") << szCustomFileName << _T(" does not exist, Error: 0x") << std::hex << GetLastError() << std::dec << "." << std::endl;
}
}
}
else {
std::cout << _T("Failed! Please select the following the right number between 1 - 3.") << std::endl;
}
system("pause");
return 0;
}