00001 00006 #include "../dllkit/dllkit.h" 00007 #include "../usrmsgs.h" 00008 #include <stdio.h> 00009 #include <tchar.h> 00010 00012 HANDLE hThisModule; 00014 MSGLIST Msgs; 00017 INITDLLSTRUCT info; 00018 00020 BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, 00021 LPVOID lpReserved) 00022 { 00023 // Save copy of handle to this module 00024 hThisModule = hModule; 00025 switch (ul_reason_for_call) { 00026 case DLL_PROCESS_ATTACH: 00027 // Create list of messages to be forwarded to this plugin 00028 CreateMsgList(&Msgs, 2); 00029 break; 00030 case DLL_PROCESS_DETACH: 00031 // Free this list 00032 FreeMsgList(&Msgs); 00033 break; 00034 } 00035 return TRUE; 00036 } 00037 00041 DLLEXPORT void __cdecl InitDll(INITDLLSTRUCT* ids, INITDLLINFO* idi) 00042 { 00043 // Fill the msglist with messages we want handle 00044 AddMessage(Msgs, CPURUNNING); 00045 AddMessage(Msgs, CPUSTOPPED); 00046 00047 // Copy informations passed to this dll 00048 info.CSMemory = ids->CSMemory; 00049 info.hInst = ids->hInst; 00050 info.hWnd = ids->hWnd; 00051 info.memory = ids->memory; 00052 info.memgetb = ids->memgetb; 00053 info.memsetb = ids->memsetb; 00054 info.optional = ids->optional; 00055 info.hTb = ids->hTb; 00056 00057 00058 // Fill the return idi structure 00059 // This reserves IO memory area IOLO + 21 to IOLO + 30 for this plugin 00060 // After accesing this area, IOFunc will be called 00061 idi->iolo = IOLO + 21; 00062 idi->iohi = IOLO + 30; 00063 idi->msglist = Msgs; 00064 } 00065 00069 DLLEXPORT void __cdecl OnMessage(MESSAGEDLLSTRUCT* mds) 00070 { 00071 switch (mds->message) { 00072 case CPURUNNING: 00073 Running = TRUE; 00074 break; 00075 case CPUSTOPPED: 00076 Running = FALSE; 00077 break; 00078 } 00079 00080 } 00081 00083 #define IOSETGET(GVAR, SVAR) \ 00084 if (mode == IOREAD) { \ 00085 *data = GVAR; \ 00086 } \ 00087 else { \ 00088 SVAR = *data; \ 00089 } 00090 00091 00095 DLLEXPORT void __cdecl IOFunc(UINT adr, unsigned char* data, iomode mode) 00096 { 00097 switch (adr) { 00098 case IOLO + 21: 00099 if (mode == IOREAD) { 00100 // set *data according to local state 00101 } 00102 else { 00103 // set local variables / perform some actions accoring to *data 00104 } 00105 break; 00106 } 00107 } 00108