This post kind of goes along with my previous post "String Initialization
and DLLs".
I have found another situation that causes the problems with my application.
If I have a DLL with a function exported and then call that function in my
application then the TApplication::OnActivate, TApplication::OnDeactivate,
and minimization messages aren't processed. To avoid any confusion here is
my code.
The DLLMAIN files are part of the dll. The APPMAIN file is the CPP part of
the main form of the application. There is nothing special about the form
// ----DLLMAIN.H----
#ifndef dllmainH
#define dllmainH
#undef DLL_I_E__
#ifdef DLLMAIN_DEFINITIONS__
#define DLL_I_E__ __declspec(dllexport)
#else
#define DLL_I_E__ __declspec(dllimport)
#endif // #ifdef DLLMAIN_DEFINITIONS__
void __fastcall DLL_I_E__ ShowIt(int Message);
#endif
// ----DLLMAIN.CPP----
#include <vcl.h>
#pragma hdrstop
#define DLLMAIN_DEFINITIONS__
#include "dllmain.h"
#pragma package(smart_init)
void __fastcall ShowIt(int Message)
{
ShowMessage(IntToStr(Message));
}
// ----APPMAIN.CPP----
#include <vcl.h>
#pragma hdrstop
#include "appmain.h"
#include "dllmain.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner)
{
ShowIt(0);
}
What am I doing wrong? This is in CBuilder 4 Pro, all patches. Both the
DLL and the application are set to build with packages and dynamic RTL.
- Clayton
1) Call Application.CreateHandle in your main CPP-file (of your EXE) before
any other method of Application is called. This creates the missing
Application.Handle.
(I do it this way)
2) Link your DLL dynamically and not statically. In this case the EXE is
initialized
before the DLL.
Hope this helps
Dirk Seifert
Clayton M. Arends <car...@evisions.com> schrieb in im Newsbeitrag:
80cmic$k3...@forums.borland.com...
Thanks for your suggestions. I guess I thought I knew all of what building
with the packages did for me but obviously I didn't. I thought packages
would just function as a DLL and put all the VCL code external so that my
executable sizes would be smaller. Thanks to your explanation I am slowly
gaining a better grasp of this stuff.
So since your second suggestion isn't an option for this application (it may
be for others) I can either turn building with run time packages off (and
increase all my EXE and DLL file sizes) or add one line of code. Hmmm...let
me think...
I put the Application->CreateHandle() before the automatic
Application->Initialize() and I have my events again. Thank you so much.
That is one thing I never would have found out on my own. Even the help
says not to call CreateHandle directly.
In your debt,
Clayton
- Clayton
>I thought packages
>would just function as a DLL and put all the VCL code external so that my
>executable sizes would be smaller.
They do - but packages initialize, too - and in your case the loading
order is
* DLL (statically linked)
* EXE
Since the DLL is loaded first, the DLL "gets" the Application object - and
that is the problem, because it should be in the EXE.
>I can either turn building with run time packages off
Nope. You just need to turn it off for either the DLL or the EXE.
>That is one thing I never would have found out on my own.
Hint: try a searching engine next time, for instance the one referenced
below. I posted a long analysis of this behaviour at least twice to these
groups in the past.
--
General information:
* Post to the right group - http://www.borland.com/newsgroups/
* Do not cross- or multipost
* Research at http://www.mers.com/searchsite.html
Stefan Hoffmeister - http://www.econos.de/
(TeamB - http://www.teamb.com/)
>are there anymore surprises that I should be aware of because of this trick?
Plenty - your application object is messed up.
Simply don't build the EXE with packages and all will be fine.
Dirk Seifert
(sorry Stefan I hit the wrong button yesterday, please apologize the email)
>I can't agree that it is messed up (although I did'nt notice the icon
>problem). Can you explain further what you mean with messed up.
In my book, the application is messed up if the Application VCL object is
not in the least properly initialized.
This has pretty subtle side-effects and the best solution is not to have
the DLL "own" the Application object.
At the first look into the VCL-source I just saw one line that cares
about EXE/DLL. Its "if not IsLibrary then CreateHandle;" in the
constructor of TApplication. This may result in side effects, but I
did not see any and did not hear about any besides the icon problem.
So I think I will stick to my solution until something else is proven.
But if it is such a problem, why does'nt Borland address it.
It should be possible, to share the standard packages between
an EXE and DLL's written in ObjectPascal.
Dirk Seifert
>I just saw one line that cares
>about EXE/DLL.
It is not about EXE/DLL. It is about who owns what, where.
>So I think I will stick to my solution until something else is proven.
Well, you are certainly free to do that.
>But if it is such a problem, why does'nt Borland address it.
>It should be possible, to share the standard packages between
>an EXE and DLL's written in ObjectPascal.
It definitely is. You have two options
a) Don't statically link the DLL(s) that have been built with packages
b) Don't use runtime packages in the DLL **and** the EXE.
If you do neither - no problem.