Для примера приведу полный код плагина tommci.plg.dll, который берет на себя проигрывание и управление музыкой в мышках и спелеологисте.
#include <windows.h>
typedef const wchar_t* __stdcall (*wcsFn)(const wchar_t*,const wchar_t*,const wchar_t*);
wcsFn RunText;
//==============================================================================
// музыка
//-------------------------------
bool SoundOn=true;
bool MusicOn=true;
wchar_t mciErrBuf[256]; //bufer для ошибок mci
const wchar_t*mciCommand=0;
DWORD Err;
bool LoopExit=false;
DWORD WINAPI mciLoop(LPVOID Param)
{ while(!LoopExit)
{ if(mciCommand)
{ Err=mciSendStringW(mciCommand,0,0,0);
mciCommand=0;
}
Sleep(100);
}
return 0;
}
//-------------------------------
const wchar_t* __fastcall MCI(const wchar_t*Login,const wchar_t*Text)
{ if(!Text||!Text[0]) return L"ожидалась команда MCI";
mciCommand=Text;
for(int i=0; i<30 && mciCommand; i++) Sleep(100); //ждем выполнения 3 секунды
if(Err)
{ if(Err==343) //343 - не установлено MIDI
{ SoundOn=false;
MusicOn=false;
}
if(mciGetErrorStringW(Err,mciErrBuf,256))
return mciErrBuf;
else
return L"неопознанная ошибка MCI";
}
return 0;
}
//-------------------------------
const wchar_t* __stdcall MusicFn(const wchar_t*Login,const wchar_t*Text,const wchar_t*)
{ if(MusicOn&&SoundOn) return MCI(Login,Text);
return 0;
}
const wchar_t* __stdcall MusicOnFn(const wchar_t*Login,const wchar_t*,const wchar_t*)
{ MusicOn=true;
if(RunText) RunText(Login,L"OnMusic(true)",0);
return L"\nмузыка включена";
}
const wchar_t* __stdcall MusicOffFn(const wchar_t*Login,const wchar_t*,const wchar_t*)
{ MusicOn=false;
if(RunText) RunText(Login,L"OnMusic(false)",0);
return L"\nмузыка выключена";
}
//-------------------------------
// звуки
//-------------------------------
const wchar_t* __stdcall SoundFn(const wchar_t*Login,const wchar_t*Text,const wchar_t*)
{ if(SoundOn) return MCI(Login,Text);
return 0;
}
const wchar_t* __stdcall SoundOnFn(const wchar_t*Login,const wchar_t*,const wchar_t*)
{ SoundOn=true;
return L"\nзвук включен";
}
const wchar_t* __stdcall SoundOffFn(const wchar_t*Login,const wchar_t*,const wchar_t*)
{ SoundOn=false;
return L"\nзвук выключен";
}
//==============================================================================
HINSTANCE EngineDll;
typedef int __stdcall (*wcsRegFn)(const wchar_t*,wcsFn,int);
enum{ FnInput=1, FnOutput=2, FnOther=3 };
wcsRegFn RegFunction=NULL;
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
switch(reason)
{ case DLL_PROCESS_ATTACH:
{ //получаем функции движка
EngineDll=GetModuleHandle("tom.dll"); //движок уже загружен
if(!EngineDll) break;
RegFunction = (wcsRegFn)GetProcAddress(EngineDll,"RegFunction");
if(!RegFunction) break;
RunText = (wcsFn)GetProcAddress(EngineDll,"RunText");
//регистрируем свои функции
RegFunction(L"music", MusicFn, FnOutput);
RegFunction(L"включить музыку", MusicOnFn, FnOutput);
RegFunction(L"вкл музыку", MusicOnFn, FnOutput);
RegFunction(L"музыка", MusicOnFn, FnOutput);
RegFunction(L"выключить музыку",MusicOffFn,FnOutput);
RegFunction(L"выкл музыку", MusicOffFn,FnOutput);
RegFunction(L"без музыки", MusicOffFn,FnOutput);
RegFunction(L"sound", SoundFn, FnOutput);
RegFunction(L"media", SoundFn, FnOutput); //альтернативное название для совместимости c 0.9.3.1 beta
RegFunction(L"включить звук", SoundOnFn, FnOutput);
RegFunction(L"включить звуки", SoundOnFn, FnOutput);
RegFunction(L"вкл звук", SoundOnFn, FnOutput);
RegFunction(L"вкл звуки", SoundOnFn, FnOutput);
RegFunction(L"звук", SoundOnFn, FnOutput);
RegFunction(L"звуки", SoundOnFn, FnOutput);
RegFunction(L"выключить звук", SoundOffFn,FnOutput);
RegFunction(L"выключить звуки",SoundOffFn,FnOutput);
RegFunction(L"выкл звук", SoundOffFn,FnOutput);
RegFunction(L"выкл звуки", SoundOffFn,FnOutput);
RegFunction(L"без звука", SoundOffFn,FnOutput);
RegFunction(L"без звуков", SoundOffFn,FnOutput);
//запускаем цикл
DWORD ThreadId;
HANDLE LoopThread=CreateThread(0,0,mciLoop,0,CREATE_SUSPENDED,&ThreadId);
ResumeThread(LoopThread);
} break;
case DLL_PROCESS_DETACH:
//останавливаем цикл
LoopExit=true;
break;
}
return 1;
}
(или hge.dll - это тоже плагин?).
.

).

