Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLL and non modal form

Status
Not open for further replies.

dufduf

Programmer
Nov 11, 2009
3
0
0
PL
I add Form1 to dll project using File->New->Form in dll project.

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);
}
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?
 
Try (pun intended):
Code:
#include "Unit1.h"
extern "C" __declspec (dllexport) void Funkcja()
{
  TForm1* newform = new TForm1(Form1);
  try
  {
    newform->Show();
  }
  __finally
  {
    delete newform;
  }
}


James P. Cottingham
[sup]I'm number 1,229!
I'm number 1,229![/sup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top