-
Notifications
You must be signed in to change notification settings - Fork 0
/
General.cpp
269 lines (227 loc) · 6.7 KB
/
General.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/// =====================================================================================
//
// The following routines are used internally by MMF, and should not need to be modified
//
// =====================================================================================
#include "common.h"
HINSTANCE hInstLib;
EXT_INIT()
// ============================================================================
//
// LIBRARY ENTRY & QUIT POINTS
//
// ============================================================================
// -----------------
// Entry points
// -----------------
// Usually you do not need to do any initialization here: it is preferable to
// do it in "Initialize" found in Edittime.cpp
BOOL WINAPI DllMain(HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
{
conditionsInfos = getConditionInfos();
actionsInfos = getActionInfos();
expressionsInfos = getExpressionInfos();
ConditionJumps = getConditions();
ActionJumps = getActions();
ExpressionJumps = getExpressions();
switch (dwReason)
{
// DLL is attaching to the address space of the current process.
case DLL_PROCESS_ATTACH:
hInstLib = hDLL; // Store HINSTANCE
break;
// A new thread is being created in the current process.
case DLL_THREAD_ATTACH:
break;
// A thread is exiting cleanly.
case DLL_THREAD_DETACH:
break;
// The calling process is detaching the DLL from its address space.
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
// -----------------
// Initialize
// -----------------
// Where you want to do COLD-START initialization.
// Called when the extension is loaded into memory.
//
extern "C" int WINAPI DLLExport Initialize(mv _far *mV, int quiet)
{
// No error
return 0;
}
// -----------------
// Free
// -----------------
// Where you want to kill and initialized data opened in the above routine
// Called just before freeing the DLL.
//
extern "C" int WINAPI DLLExport Free(mv _far *mV)
{
// No error
return 0;
}
// ============================================================================
//
// GENERAL INFO
//
// ============================================================================
// -----------------
// Get Infos
// -----------------
//
extern "C"
{
DWORD WINAPI DLLExport GetInfos(int info)
{
switch (info)
{
case KGI_VERSION:
return EXT_VERSION2;
case KGI_PLUGIN:
return EXT_PLUGIN_VERSION1;
case KGI_PRODUCT:
return ForVersion;
case KGI_BUILD:
return MinimumBuild;
case KGI_UNICODE:
#ifdef _UNICODE
return TRUE;
#else
return FALSE;
#endif
default:
return 0;
}
}
}
// ----------------------------------------------------------
// GetRunObjectInfos
// ----------------------------------------------------------
// Fills an information structure that tells MMF2 everything
// about the object, its actions, conditions and expressions
//
short WINAPI DLLExport GetRunObjectInfos(mv _far *mV, fpKpxRunInfos infoPtr)
{
infoPtr->conditions = (LPBYTE)ConditionJumps;
infoPtr->actions = (LPBYTE)ActionJumps;
infoPtr->expressions = (LPBYTE)ExpressionJumps;
infoPtr->numOfConditions = Conditions.size();
infoPtr->numOfActions = Actions.size();
infoPtr->numOfExpressions = Expressions.size();
infoPtr->editDataSize = sizeof(EDITDATA);
MagicFlags(infoPtr->editFlags);
infoPtr->windowProcPriority = WINDOWPROC_PRIORITY;
MagicPrefs(infoPtr->editPrefs);
infoPtr->identifier = IDENTIFIER;
infoPtr->version = ObjectVersion;
return TRUE;
}
// ----------------------------------------------------------
// GetDependencies
// ----------------------------------------------------------
// Returns the name of the external modules that you wish MMF to include
// with stand-alone applications (these modules must be in the MMF
// Data\Runtime folder).
//
LPCSTR* WINAPI DLLExport GetDependencies()
{
// Do some rSDK stuff
#include "rGetDependencies.h"
//LPCSTR szDep[] = {
// "MyDll.dll",
// NULL
//};
return NULL; // szDep;
}
// -----------------
// LoadObject
// -----------------
// Routine called for each object when the object is read from the MFA file (edit time)
// or from the CCN or EXE file (run time).
// You can load data here, reserve memory etc...
//
int WINAPI DLLExport LoadObject(mv _far *mV, LPCSTR fileName, LPEDATA edPtr, int reserved)
{
return 0;
}
// -----------------
// UnloadObject
// -----------------
// The counterpart of the above routine: called just before the object is
// deleted from the frame.
//
void WINAPI DLLExport UnloadObject(mv _far *mV, LPEDATA edPtr, int reserved)
{
}
// --------------------
// UpdateEditStructure
// --------------------
// For you to update your object structure to newer versions
// Called at both edit time and run time
//
HGLOBAL WINAPI DLLExport UpdateEditStructure(mv __far *mV, void __far * OldEdPtr)
{
#ifdef UNICODE
// Update ANSI to Unicode EDITDATA
if (!mvIsUnicodeApp(mV, mV->mvEditApp))
{
if(HGLOBAL hgNew = GlobalAlloc(GPTR, sizeof(EDITDATAW)))
{
EDITDATAA* ansiPtr = (EDITDATAA*)OldEdPtr;
EDITDATAW* edPtr = (EDITDATA*)GlobalLock(hgNew);
memcpy(&edPtr->eHeader, &ansiPtr->eHeader, sizeof(extHeader));
edPtr->eHeader.extVersion = ObjectVersion;
edPtr->eHeader.extSize = sizeof(EDITDATAW);
// Copy non-text stuff
memcpy(&edPtr->width, &ansiPtr->width, (size_t)&ansiPtr->textFont.lfFaceName[0] - (size_t)&ansiPtr->width);
edPtr->textColor = ansiPtr->textColor;
edPtr->textFlags = ansiPtr->textFlags;
// Convert font face
MultiByteToWideChar(mvGetAppCodePage(mV, mV->mvEditApp), 0, ansiPtr->textFont.lfFaceName, -1, edPtr->textFont.lfFaceName, LF_FACESIZE);
GlobalUnlock(hgNew);
return (HGLOBAL)hgNew;
}
}
#endif
return 0;
}
// --------------------
// UpdateFileNames
// --------------------
// If you store file names in your datazone, they have to be relocated when the
// application is moved to a different directory: this routine does it.
// Called at edit time and run time.
//
// Call lpfnUpdate to update your file pathname (refer to the documentation)
//
void WINAPI DLLExport UpdateFileNames(mv _far *mV, LPSTR appName, LPEDATA edPtr, void (WINAPI * lpfnUpdate)(LPSTR, LPSTR))
{
}
// ---------------------
// EnumElts
// ---------------------
//
// Uncomment this function if you need to store an image in the image bank.
//
// Note: do not forget to enable the function in the .def file
// if you remove the comments below.
//
int WINAPI DLLExport EnumElts (mv __far *mV, LPEDATA edPtr, ENUMELTPROC enumProc, ENUMELTPROC undoProc, LPARAM lp1, LPARAM lp2)
{
int error = FALSE;
// Enum images
for(int i=0;i<edPtr->imageCount;i++) {
error = enumProc(&edPtr->images[i],IMG_TAB,lp1,lp2);
if(error) {
// Undo enum images
for(int j=i-1;j>=0;j--)
undoProc(&edPtr->images[j],IMG_TAB,lp1,lp2);
break;
}
}
return error;
}