program WIN32DLL 'PLUGIN';
#include 'zirplug/framework.zir';
#include 'ch.zir';
//////////////////////////////
const strLoaded = 'Plugin has loaded!';
//////////////////////////////
int32 bufSize;
char* strSource;
//////////////////////////////
//
// This function can be done much better than this.
//
procedure emitLine(char* line) {
uses edi;
if (strAppend(strSource, line, bufSize) == false) {
push edi;
add bufSize, 2048
edi = malloc(bufSize);
eax = strLen(strSource);
strlcpy(edi, strSource, eax);
freemem(strSource);
strSource = edi;
//now append it, maybe should check line is not 2048 bytes long :-p
strAppend(strSource, line, bufSize);
pop edi
}
}
function InitPlugin(pointer pGetF) {
Ziron_LoadAll(pGetF); //use framework utility function to load all
bufSize = 2048;
strSource = malloc(2048);
return strLoaded;
}
function UnloadPlugin() {
//free strSource here
freemem(strSource);
}
function FileEntry(DWord handle; char* code) {
uses edi;
eax = strSource;
char*[eax] = 0;
//your usual code here
char inte[32];
char tmp[2048];
edi = strGetLine(code, @tmp);
while(edi <> 0) {
strAppend(@tmp, '\r\n', 2048);
emitLine(@tmp);
edi = strGetLine(edi, @tmp);
}
Ziron_ShowMessage(strSource);
Ziron_SetFileBuffer(handle, strSource, strLen(strSource));
}
entry function DLLMain(DWord iDLL; DWord iReason; Pointer iResult) {
if (iReason == DLL_PROCESS_ATTACH) {
return true;
}
return false;
}
exports InitPlugin, UnloadPlugin, FileEntry;