I add Form1 to dll project using File->New->Form in dll project.
DLL project
Main cpp
But I still don`t know how to close the window without system error. While the window is creating modalessly main app free library and there is access violation. How to free library on onCloseQuery event or onClose event in Form1?
DLL project
Code:
#include "Unit1.h"
extern "C" __declspec (dllexport) void Funkcja()
{
TForm1* newform = new TForm1(Form1);
newform->Show();
}
Main cpp
Code:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE DLLHandle = LoadLibrary(L"Projectmydll.dll");
if(DLLHandle != NULL)
{
typedef (*aFunkcja)();
aFunkcja Funkcja = (aFunkcja)GetProcAddress(DLLHandle, "_Funkcja");
if( Funkcja != NULL) Funkcja();
else ShowMessage( ""Lack of Funkcja" );
}
else ShowMessage( "Lack of dll." );
FreeLibrary(DLLHandle);
}