Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Bob Swart (aka Dr.Bob) - Medical Officer C++Builder 5 Developer's Guide
 Dr.Bob's Tip-Of-The-Hat #12
See Also: Delphi Papers, Columns and other Tip-Of-The-Hats

C++Builder 5 WebBroker DLLs
Some time ago, I was tring to use IntraBob to debug an ISAPI web module written in C++Builder 5 Enterprise. The program seems to run fine until I receive an exception saying "only one data module per application".
As also explained in detail in my WebBroker chapter of the C++Builder Developer's Guide, this appears to be a bug in the way C++Builder WebBroker projects create web module instances. In the ISAPI main project file, you'll find the following code for the main loop:

  int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
  {
    try
    {
      Application->Initialize();
      Application->CreateForm(__classid(TWebModule1), &WebModule1);
      Application->Run();
    }
    catch (Exception &exception)
    {
    } return 1;
  }
Note that this code will generate a web module every time DLLEntryPoint is called. However, the DLLEntryPoint function is not only called then the DLL is loaded, but can be called for several reasons (the value of reason), including - you guessed it - when the DLL is closing down.
In order to prevent the exception from happening, you should change the code to make sure it only creates an instance of the web module when reason is equal to DLL_PROCESS_ATTACH:
  if (reason == DLL_PROCESS_ATTACH)
    Application->CreateForm(__classid(TWebModule1), &WebModule1);
This solves the problem nicely...


This webpage © 2001-2009 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.