//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#include "DLLMain.h"
#include "DLLForm.h"
#pragma hdrstop
//---------------------------------------------------------------------------
// This will be provided by the EXE when the form is created.
DLL_CALLBACK Callback = 0;
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
// We own the form, we have to delete it.
if (reason == DLL_PROCESS_DETACH)
delete frmDLL;
return 1;
}
//---------------------------------------------------------------------------
// Copy the values from the UI components into the data struct.
void UItoData(FormData *data)
{
data->map = frmDLL->rgrpMap->ItemIndex;
data->spectre = frmDLL->chkSpectre->Checked;
data->arachnotron = frmDLL->chkArachnotron->Checked;
data->mancubus = frmDLL->chkMancubus->Checked;
data->spectre_count = StrToInt(frmDLL->edtNumSpectre->Text);
data->arachnotron_count = StrToInt(frmDLL->edtNumArachnotron->Text);
data->mancubus_count = StrToInt(frmDLL->edtNumMancubus->Text);
// These strncpy calls may be inefficient if the source strings
// are very small, in which case it would be faster to just copy
// the non-NUL characters.
strncpy(data->title, frmDLL->edtTitle->Text.c_str(), MAX_STRLEN);
data->title[MAX_STRLEN - 1] = 0;
strncpy(data->description, frmDLL->edtDescription->Text.c_str(), MAX_STRLEN);
data->description[MAX_STRLEN - 1] = 0;
}
// Create the form and store the callback function pointer for later use.
void __stdcall CreateForm(DLL_CALLBACK cb)
{
frmDLL = new TfrmDLL(NULL); // Don't forget to free this
Callback = cb;
}
//---------------------------------------------------------------------------
// Toggle the form between hidden and visible. I'm using an integer
// instead of a bool because not all languages represent a boolean
// the same way. Almost all languages can deal with (signed 32-bit)
// integers.
void __stdcall ShowForm(int show)
{
if (show)
frmDLL->Show();
else
frmDLL->Hide();
}
//---------------------------------------------------------------------------
// The EXE will call this function to retrieve the data fields.
void __stdcall GetData(FormData *data)
{
UItoData(data);
}