[comp.windows.ms.programmer] Borland C++ and exports

jdb@reef.cis.ufl.edu (Brian K. W. Hook) (04/07/91)

Can someone please explain to me when I do and do not need to use the
_export keyword or a .DEF file?  I was under the impressio that normally
you export a function that Windows will be calling directly.  E.g.
MainWndProc.  Now, using the Guide to Programming GENERIC works just fine
if I have "All functions exportable" checked off with no explicit exports
anywhere.  I just use the default .DEF file.

HOWEVER....the minute I add a LoadBitmap() to MainWndProc(), it dies at
that line with a UAE.  HOWEVER....when I use Smart Callbacks, it works.


What am I doing wrong or just not understanding?

Brian

cadsi@ccad.uiowa.edu (CADSI) (04/08/91)

From article <27869@uflorida.cis.ufl.EDU>, by jdb@reef.cis.ufl.edu (Brian K. W. Hook):
> 
> Can someone please explain to me when I do and do not need to use the
> _export keyword or a .DEF file?  I was under the impressio that normally
> you export a function that Windows will be calling directly.  E.g.
> MainWndProc.  Now, using the Guide to Programming GENERIC works just fine
> if I have "All functions exportable" checked off with no explicit exports
> anywhere.  I just use the default .DEF file.
> 
> HOWEVER....the minute I add a LoadBitmap() to MainWndProc(), it dies at
> that line with a UAE.  HOWEVER....when I use Smart Callbacks, it works.

Any 'window' procedure needs to be exported.  That includes dialogs.  Unless
you use the smart callback feature, you'll have to make the code thunk for
dialog procedures (MakeProcInstance()).  In addition any callback that
will be used for Enumerating fonts, tasks and that stuff.

You use the _export on any function that you don't want to have to
declare in the .def file.  Now, you don't call MakeProcInstance on
all exported functions because Windows does this for you in the Register()
and CreateWindow() calls.

Lastly, IF you use the _export keyword exclusively you can use the -WE
switch on bcc.  If you intersperse _export'ed type functions with functions
not export'ed that will be called by Windows, you absolutely need to the
functions not declared with _export in the .def file.

My opinion, Its really easier to use the _export keyword.  Just put it on
ALL callback type functions and compile with the export Windows Explicit
option set to on.  That way, all the right things will happen during the
linking stage (which is actually where the info about exporting is used).

Oooohhh, ick, that above looks like spaghetti.

Ok, here are the rules:
1)
	Window callback functions		needs _export.
	Dialog procedures			needs _export.
	Enumeration callbacks			needs  _export.
	standard C calls			don't need anything special.
	your standard functions			don't need anything special.
	
2)
	Window callback functions		don't need MakeProcInstance
	Dialog procedures			need MakeProcInstance
	Enumeration callbacks			need MakeProcInstance
						smart callback feature
	standard C calls			just call 'em and forget 'em
	your standard functions			just call 'em and forget 'em

I hope this helps you AND others.  Its a pity everybody didn't start with
the SDK.  Even though it ain't great, you had to learn all this stuff
no matter what.  Microsoft is not so nice as to add _export keywords
and smart callback features (at least yet anyway).

|----------------------------------------------------------------------------|
|Tom Hite					|  The views expressed by me |
|Manager, Product development			|  are mine, not necessarily |
|CADSI (Computer Aided Design Software Inc.	|  the views of CADSI.       |
|----------------------------------------------------------------------------|