//dllmain.cpp
// dllmain.cpp : Определяет точку входа для приложения DLL.
#include "pch.h"
#include "crsWrapper.h"
#include <windows.h>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
crsInitDll();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// crsWrapper.h
#pragma once
void crsInitDll();
extern "C" __declspec(dllexport) void* crsPipeWrapper(int fnId);
// crsWrapper.cpp
#include <iostream>
#include "pch.h"
#include "crsWrapper.h"
#include <windows.h>
// объявим тип данных функции
typedef int (*crsGetStringType)(void *, int, char *Destination, int Count);
typedef int (*GetMapDescriptionsType)(int mapCode, char *destMapKey, char* destMapName, char* destMapPoem1, char* destMapDesc, char* destMapPoem2);
crsGetStringType crsGetString = NULL;
int GetMapDescriptions(int mapCode, char *destMapKey, char *destMapName, char *destMapPoem1, char *destMapDesc, char *destMapPoem2) {
if (mapCode >= 0 && mapCode <= 9) {
int result = 0;
switch (mapCode) {
case 0:
crsGetString(0, 40050, destMapKey, 32);
crsGetString(0, 40000, destMapName, 32);
crsGetString(0, 40020, destMapPoem1, 256);
crsGetString(0, 40030, destMapDesc, 256);
crsGetString(0, 40040, destMapPoem2, 256);
result = 1;
break;
case 1:
crsGetString(0, 40051, destMapKey, 32);
crsGetString(0, 40001, destMapName, 32);
crsGetString(0, 40021, destMapPoem1, 256);
crsGetString(0, 40031, destMapDesc, 256);
crsGetString(0, 40041, destMapPoem2, 256);
result = 1;
break;
case 2:
crsGetString(0, 40052, destMapKey, 32);
crsGetString(0, 40002, destMapName, 32);
crsGetString(0, 40022, destMapPoem1, 256);
crsGetString(0, 40032, destMapDesc, 256);
crsGetString(0, 40042, destMapPoem2, 256);
result = 1;
break;
case 3:
crsGetString(0, 40053, destMapKey, 32);
crsGetString(0, 40003, destMapName, 32);
crsGetString(0, 40023, destMapPoem1, 256);
crsGetString(0, 40033, destMapDesc, 256);
crsGetString(0, 40043, destMapPoem2, 256);
result = 1;
break;
case 4:
crsGetString(0, 40054, destMapKey, 32);
crsGetString(0, 40004, destMapName, 32);
crsGetString(0, 40024, destMapPoem1, 256);
crsGetString(0, 40034, destMapDesc, 256);
crsGetString(0, 40044, destMapPoem2, 256);
result = 1;
break;
case 5:
crsGetString(0, 40055, destMapKey, 32);
crsGetString(0, 40005, destMapName, 32);
crsGetString(0, 40025, destMapPoem1, 256);
crsGetString(0, 40035, destMapDesc, 256);
crsGetString(0, 40045, destMapPoem2, 256);
result = 1;
break;
case 6:
crsGetString(0, 40056, destMapKey, 32);
crsGetString(0, 40006, destMapName, 32);
crsGetString(0, 40026, destMapPoem1, 256);
crsGetString(0, 40036, destMapDesc, 256);
crsGetString(0, 40046, destMapPoem2, 256);
result = 1;
break;
case 7:
crsGetString(0, 40057, destMapKey, 32);
crsGetString(0, 40007, destMapName, 32);
crsGetString(0, 40027, destMapPoem1, 256);
crsGetString(0, 40037, destMapDesc, 256);
crsGetString(0, 40047, destMapPoem2, 256);
result = 1;
break;
case 8:
crsGetString(0, 40058, destMapKey, 32);
crsGetString(0, 40008, destMapName, 32);
crsGetString(0, 40028, destMapPoem1, 256);
crsGetString(0, 40038, destMapDesc, 256);
crsGetString(0, 40048, destMapPoem2, 256);
result = 1;
break;
case 9:
crsGetString(0, 40059, destMapKey, 32);
crsGetString(0, 40009, destMapName, 32);
crsGetString(0, 40029, destMapPoem1, 256);
crsGetString(0, 40039, destMapDesc, 256);
crsGetString(0, 40049, destMapPoem2, 256);
result = 1;
break;
}
return result;
}
else
{
return 0;
}
}
void* crsPipeWrapper(int fnId) {
switch (fnId) {
case 1:
return reinterpret_cast<void*>(GetMapDescriptions);
default:
return nullptr;
}
}
void _initExeImportFunctions() {
HMODULE hModule = GetModuleHandle(NULL);
if (hModule == NULL) {
MessageBoxA(NULL, "crs.dll can't import exe file functions. This is bad!=(", "Info", MB_OK);
return;
}
char crsGetStringName[] = "_crsGetString@16";
crsGetString = (crsGetStringType)GetProcAddress(hModule, crsGetStringName);
if (crsGetString == NULL) {
MessageBoxA(NULL, "Функция _crsGetString@16 не найдена! Ошибка неизбежна..", "Info", MB_OK);
}
}
void crsInitDll() {
MessageBoxA(NULL, "Is succefully load crs.dll! This is good!=)", "Info", MB_OK);
__initExeImportFunctions();
}