Next we add this import library to our project that uses this very simple test
DLL. When we try to run it, the program is loaded and immediately terminates
before entering our main function (WinMain() normally, although we use Inmark's
zApp, so it's zApp::main()).
Giving up on this we then tried simple C functions in the DLL such as:
extern "C" {
int FAR PASCAL _export plusOne ( char * string );
}
etc...
As long as we don't actually try to use any of the functions now
in the DLL the application runs. Our LibMain function in the DLL contains a
simple MessageBox call so we know when it loads. Quite correctly, this isn't
called: the DLL isn't used, and hence isn't loaded during the preload sequence.
If, however, we call any of the DLL functions, the application again loads and
immediately terminates before entering our main function. The MessageBox in
the DLL's LibMain does not get called either.
Finally we tried doing an explicit LoadLibrary on the DLL. If this was
successfull we followed up with a call to GetProcAddress, a call to the
function through the procedure address, and then
a FreeLibrary. This works perfectly! The LibMain MessageBox appears, the
DLL function works etc. But obviously, for C++ classes, this isn't really
going to work too well!!
As far as the .DEF module definition files for the DLL and our test harness go,
we've tried adding the DLL's exported functions to it's .DEF exports section,
but figured that the import library would do the rest in our test harness. No
such luck though.
Any cunning ideas why the program loads and unloads before beginning to
execute?
Cheers,
--
Stuart Booth
stu...@garage.demon.co.uk
I can "help" you with this last bit. You cannot create a window
in the LibMain of an implicitly loaded DLL (and a MessageBox is a
window). This is because LibMain is loaded and executed at a time
that the main application's message queue hasn't been set up yet.
If you load the DLL explicitly at a later time, MessageBox() will
work normally, as you have experienced.
--
Miguel Carrasquer ____________________ ~~~
Amsterdam [ ||]~
m...@inter.NL.net ce .sig n'est pas une .cig
>I can "help" you with this last bit. You cannot create a window
>in the LibMain of an implicitly loaded DLL (and a MessageBox is a
>window). This is because LibMain is loaded and executed at a time
>that the main application's message queue hasn't been set up yet.
>If you load the DLL explicitly at a later time, MessageBox() will
>work normally, as you have experienced.
That's absolutely correct.
Also keep in mind that a DLL does NOT have a message queue of his own !!!
( It "borrows" the Main Apps queue )
Hope you get it working
Ciao
OLI
P.S.: Please EMail me directly, if possible !
=======================================================================
Oliver Pistor EMail: pis...@pips01.informatik.uni-mannheim.de
Universitaet Mannheim
Germany
----------------------------------------------------------------------
Open your eyes and you can see the flames of your wasted life
( Counting Crows: " A murder of one " )
----------------------------------------------------------------------
A man who stands for nothing will fall for anything ( Malcom X )
=======================================================================
--