Thanks. But what do you mean saying "close the window before unloading the library"? Close in main app or in DLL? Function return pointer to main app so in what way I have to do it? Do I have to send a pointer to dll?
void __fastcall TForm1::Button1Click(TObject *Sender)
{
HINSTANCE DLLHandle = LoadLibrary(L"Project1.dll");
TForm* form;
if(DLLHandle != NULL)
{
typedef TForm* (*aFunkcja)(TForm**);
typedef void (*aClose)(TForm**);
aFunkcja Funkcja = (aFunkcja)GetProcAddress(DLLHandle, "_Funkcja");
aClose Close = (aClose)GetProcAddress(DLLHandle, "_Close");
if( Funkcja != NULL ) form = Funkcja( &form );
if ( !form ) return;
Close( &form );
}
else ShowMessage( "Lack of dll." );
FreeLibrary(DLLHandle);
}
extern "C" __declspec(dllexport) TForm* Funkcja(TForm** form)
{
*form = new TForm1(Form1);
(*form)->Show();
return *form;
}
void Close( TForm** form )
{
delete *form;
}
Form is creating non modal but while is visible there is access violation.