| 1 |
#include "NsmPluginMain.h" |
| 2 |
|
| 3 |
#include <vector> |
| 4 |
|
| 5 |
#include <shlwapi.h> |
| 6 |
#if defined(_MSC_VER) |
| 7 |
#pragma comment(lib, "shlwapi.lib") |
| 8 |
#endif |
| 9 |
|
| 10 |
#include "dummy.h" |
| 11 |
|
| 12 |
extern HINSTANCE g_hInstance; |
| 13 |
|
| 14 |
namespace Regnessem |
| 15 |
{ |
| 16 |
namespace Common |
| 17 |
{ |
| 18 |
// NsmPluginMain -------------------------------------------------------------- |
| 19 |
|
| 20 |
NsmPluginMain::NsmPluginMain() |
| 21 |
:Initialized() |
| 22 |
{ |
| 23 |
PluginInfo[NMPI_APIVER] = NSM_API_VERSION; |
| 24 |
} |
| 25 |
|
| 26 |
NsmPluginMain::~NsmPluginMain() |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
void NsmPluginMain::Initialize(const TNsmPluginInitInfo& initInfo) |
| 31 |
{ |
| 32 |
if(!Initialized) |
| 33 |
{ |
| 34 |
Initialized = true; |
| 35 |
InitInfo = initInfo; |
| 36 |
DoInitialize(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
void NsmPluginMain::Terminate() |
| 41 |
{ |
| 42 |
if(Initialized) |
| 43 |
{ |
| 44 |
Initialized = false; |
| 45 |
DoTerminate(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
void NsmPluginMain::DoInitialize() |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
void NsmPluginMain::DoTerminate() |
| 54 |
{ |
| 55 |
} |
| 56 |
|
| 57 |
tstring NsmPluginMain::GetPluginInfo(int index) const |
| 58 |
{ |
| 59 |
if(0 <= index && index < std::tuple_size<decltype(PluginInfo)>::value) |
| 60 |
return PluginInfo[index]; |
| 61 |
|
| 62 |
return tstring(); |
| 63 |
} |
| 64 |
|
| 65 |
void NsmPluginMain::SetPluginInfo(int index,const tstring &value) |
| 66 |
{ |
| 67 |
if(0 <= index && index < std::tuple_size<decltype(PluginInfo)>::value) |
| 68 |
PluginInfo[index] = value; |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
bool NsmPluginMain::IsInitialized() const |
| 73 |
{ |
| 74 |
return Initialized; |
| 75 |
} |
| 76 |
|
| 77 |
tstring NsmPluginMain::GetDllFileName() |
| 78 |
{ |
| 79 |
std::array<TCHAR, MAX_PATH> buff; |
| 80 |
GetModuleFileName(g_hInstance, buff.data(), std::tuple_size<decltype(buff)>::value); |
| 81 |
|
| 82 |
return buff.data(); |
| 83 |
} |
| 84 |
|
| 85 |
tstring NsmPluginMain::GetWorkDir() |
| 86 |
{ |
| 87 |
const tstring dllPath = GetDllFileName(); |
| 88 |
|
| 89 |
std::vector<TCHAR> path(dllPath.size() + 2); |
| 90 |
|
| 91 |
#ifdef _MSC_VER |
| 92 |
dllPath._Copy_s(&path[0], path.size(), dllPath.size()); |
| 93 |
#else |
| 94 |
dllPath.copy(&path[0], dllPath.size()); |
| 95 |
#endif |
| 96 |
|
| 97 |
PathRemoveExtension(&path[0]); |
| 98 |
PathAddBackslash(&path[0]); |
| 99 |
|
| 100 |
return &path[0]; |
| 101 |
} |
| 102 |
|
| 103 |
tstring NsmPluginMain::GetIniFileName() |
| 104 |
{ |
| 105 |
const tstring dllName = ExtractFileName(GetDllFileName()); |
| 106 |
|
| 107 |
std::vector<TCHAR> filename(dllName.size() + 1); |
| 108 |
#ifdef _MSC_VER |
| 109 |
dllName._Copy_s(&filename[0], filename.size(), dllName.size()); |
| 110 |
#else |
| 111 |
dllName.copy(&filename[0], dllName.size()); |
| 112 |
#endif |
| 113 |
|
| 114 |
PathRemoveExtension(&filename[0]); |
| 115 |
|
| 116 |
return GetWorkDir() + &filename[0] + TEXT(".ini"); |
| 117 |
} |
| 118 |
|
| 119 |
HNsmService NsmPluginMain::CreateNsmService(const tstring &serviceName,const TNsmServiceProc procAddr) const |
| 120 |
{ |
| 121 |
return InitInfo.CreateNsmService(t2c(serviceName).c_str(),procAddr); |
| 122 |
} |
| 123 |
|
| 124 |
HNsmService NsmPluginMain::GetService(const tstring &serviceName) const |
| 125 |
{ |
| 126 |
return InitInfo.GetService(t2c(serviceName).c_str()); |
| 127 |
} |
| 128 |
|
| 129 |
LONG_PTR NsmPluginMain::CallService(const tstring &serviceName,const WPARAM wParam,const LPARAM lParam) const |
| 130 |
{ |
| 131 |
HNsmService hService = GetService(serviceName); |
| 132 |
|
| 133 |
if(hService) |
| 134 |
return InitInfo.CallService(hService, wParam, lParam); |
| 135 |
|
| 136 |
return 0; |
| 137 |
} |
| 138 |
|
| 139 |
HNsmEvent NsmPluginMain::CreateNsmEvent(const tstring &eventName) const |
| 140 |
{ |
| 141 |
return InitInfo.CreateNsmEvent(t2c(eventName).c_str()); |
| 142 |
} |
| 143 |
|
| 144 |
HNsmEvent NsmPluginMain::GetEvent(const tstring &eventName) const |
| 145 |
{ |
| 146 |
return InitInfo.GetEvent(t2c(eventName).c_str()); |
| 147 |
} |
| 148 |
|
| 149 |
int NsmPluginMain::NotifyEvent(const HNsmEvent eventHandle,const WPARAM wParam,const LPARAM lParam) const |
| 150 |
{ |
| 151 |
return InitInfo.NotifyEvent(eventHandle, wParam, lParam); |
| 152 |
} |
| 153 |
|
| 154 |
int NsmPluginMain::HookEvent(const tstring &eventName,const TNsmEventProc procAddr) const |
| 155 |
{ |
| 156 |
return InitInfo.HookEvent(t2c(eventName).c_str(), procAddr); |
| 157 |
} |
| 158 |
|
| 159 |
int NsmPluginMain::UnhookEvent(const tstring &eventName,const TNsmEventProc procAddr) const |
| 160 |
{ |
| 161 |
return InitInfo.UnhookEvent(t2c(eventName).c_str(), procAddr); |
| 162 |
} |
| 163 |
} |
| 164 |
} |