www.digitalmars.com         C & C++   DMDScript  

D - winsamp.d

reply imr1984 <imr1984_member pathlink.com> writes:
Can someone explain to me why Win32 programs need these 5 externs? Cant they be
put into the std.c.windows.windows import file? Also, what is the difference
between extern and export?, because they both seem to be used to import
functions from a dll/lib. Sorry for the loads of the questions but the spec file
isnt that clear.

extern (C) void gc_init();
extern (C) void gc_term();
extern (C) void _minit();
extern (C) void _moduleCtor();
extern (C) void _moduleUnitTests();

extern (Windows)
int WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{

..
Jan 13 2004
parent reply "Walter" <walter digitalmars.com> writes:
extern (C) sets the calling convention. export sets the special protocall
used to export functions from a DLL. They are not in their own import
because they are internal names and may change.

"imr1984" <imr1984_member pathlink.com> wrote in message
news:bu1hbv$m74$1 digitaldaemon.com...
 Can someone explain to me why Win32 programs need these 5 externs? Cant
they be
 put into the std.c.windows.windows import file? Also, what is the
difference
 between extern and export?, because they both seem to be used to import
 functions from a dll/lib. Sorry for the loads of the questions but the
spec file
 isnt that clear.

 extern (C) void gc_init();
 extern (C) void gc_term();
 extern (C) void _minit();
 extern (C) void _moduleCtor();
 extern (C) void _moduleUnitTests();

 extern (Windows)
 int WinMain(HINSTANCE hInstance,
 HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,
 int nCmdShow)
 {

 ..
Jan 13 2004
next sibling parent reply "Matthew" <matthew.hat stlsoft.dot.org> writes:
 extern (C) sets the calling convention. export sets the special protocall
 used to export functions from a DLL. They are not in their own import
 because they are internal names and may change.
Can we still export functions marked extern(C) but not marked export via a .DEF file, or other means?
 "imr1984" <imr1984_member pathlink.com> wrote in message
 news:bu1hbv$m74$1 digitaldaemon.com...
 Can someone explain to me why Win32 programs need these 5 externs? Cant
they be
 put into the std.c.windows.windows import file? Also, what is the
difference
 between extern and export?, because they both seem to be used to import
 functions from a dll/lib. Sorry for the loads of the questions but the
spec file
 isnt that clear.

 extern (C) void gc_init();
 extern (C) void gc_term();
 extern (C) void _minit();
 extern (C) void _moduleCtor();
 extern (C) void _moduleUnitTests();

 extern (Windows)
 int WinMain(HINSTANCE hInstance,
 HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,
 int nCmdShow)
 {

 ..
Jan 13 2004
parent reply "Walter" <walter digitalmars.com> writes:
"Matthew" <matthew.hat stlsoft.dot.org> wrote in message
news:bu2i9h$2cn0$1 digitaldaemon.com...
 extern (C) sets the calling convention. export sets the special
protocall
 used to export functions from a DLL. They are not in their own import
 because they are internal names and may change.
Can we still export functions marked extern(C) but not marked export via a .DEF file, or other means?
The same rules apply as for C. After all, a .DEF file is a command to the linker, not the compiler, and the linker knows nothing about languages.
Jan 14 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bu2v2k$1r8$1 digitaldaemon.com...
 "Matthew" <matthew.hat stlsoft.dot.org> wrote in message
 news:bu2i9h$2cn0$1 digitaldaemon.com...
 extern (C) sets the calling convention. export sets the special
protocall
 used to export functions from a DLL. They are not in their own import
 because they are internal names and may change.
Can we still export functions marked extern(C) but not marked export via
a
 .DEF file, or other means?
The same rules apply as for C. After all, a .DEF file is a command to the linker, not the compiler, and the linker knows nothing about languages.
Thought so. Just checking. :)
Jan 14 2004
prev sibling parent reply imr1984 <imr1984_member pathlink.com> writes:
so are those 5 externs like prototypes to tell the compiler to reference the D
library? If so why cant they be put into the windows.d import file?

In article <bu1u4s$1brd$1 digitaldaemon.com>, Walter says...
extern (C) sets the calling convention. export sets the special protocall
used to export functions from a DLL. They are not in their own import
because they are internal names and may change.

"imr1984" <imr1984_member pathlink.com> wrote in message
news:bu1hbv$m74$1 digitaldaemon.com...
 Can someone explain to me why Win32 programs need these 5 externs? Cant
they be
 put into the std.c.windows.windows import file? Also, what is the
difference
 between extern and export?, because they both seem to be used to import
 functions from a dll/lib. Sorry for the loads of the questions but the
spec file
 isnt that clear.

 extern (C) void gc_init();
 extern (C) void gc_term();
 extern (C) void _minit();
 extern (C) void _moduleCtor();
 extern (C) void _moduleUnitTests();

 extern (Windows)
 int WinMain(HINSTANCE hInstance,
 HINSTANCE hPrevInstance,
 LPSTR lpCmdLine,
 int nCmdShow)
 {

 ..
Jan 14 2004
parent reply "Walter" <walter digitalmars.com> writes:
"imr1984" <imr1984_member pathlink.com> wrote in message
news:bu3lbl$15fl$1 digitaldaemon.com...
 so are those 5 externs like prototypes to tell the compiler to reference
the D
 library?
Yes.
 If so why cant they be put into the windows.d import file?
I want to keep windows.d an analogue of windows.h
Jan 14 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
Walter wrote:

"imr1984" <imr1984_member pathlink.com> wrote in message
news:bu3lbl$15fl$1 digitaldaemon.com...
  

so are those 5 externs like prototypes to tell the compiler to reference
    
the D
library?
    
Yes.
If so why cant they be put into the windows.d import file?
    
I want to keep windows.d an analogue of windows.h
Why no have a dwindows (or something), which imports all the related stuff for windows?
Jan 14 2004
parent reply J C Calvarese <jcc7 cox.net> writes:
J Anderson wrote:

 Walter wrote:
 
 "imr1984" <imr1984_member pathlink.com> wrote in message
 news:bu3lbl$15fl$1 digitaldaemon.com...
  

 so are those 5 externs like prototypes to tell the compiler to reference
   
the D
 library?
   
Yes.
 If so why cant they be put into the windows.d import file?
   
I want to keep windows.d an analogue of windows.h
Why no have a dwindows (or something), which imports all the related stuff for windows?
Are you thinking of something like this? // ----------------------------------- // module std.windows.windows; extern (C) void gc_init(); extern (C) void gc_term(); extern (C) void _minit(); extern (C) void _moduleCtor(); extern (C) void _moduleUnitTests(); // ----------------------------------- // Seems like a good idea to me. I like to keep the mysterious stuff underneath the hood. I prefer one line with "import std.windows.windows;" to five cryptic lines that make it easy for me to mess up something. -- Justin http://jcc_7.tripod.com/d/
Jan 14 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
J C Calvarese wrote:

 J Anderson wrote:

 Walter wrote:

 "imr1984" <imr1984_member pathlink.com> wrote in message
 news:bu3lbl$15fl$1 digitaldaemon.com...
  

 so are those 5 externs like prototypes to tell the compiler to 
 reference
   
the D
 library?
   
Yes.
 If so why cant they be put into the windows.d import file?
   
I want to keep windows.d an analogue of windows.h
Why no have a dwindows (or something), which imports all the related stuff for windows?
Are you thinking of something like this? // ----------------------------------- // module std.windows.windows; extern (C) void gc_init(); extern (C) void gc_term(); extern (C) void _minit(); extern (C) void _moduleCtor(); extern (C) void _moduleUnitTests(); // ----------------------------------- // Seems like a good idea to me. I like to keep the mysterious stuff underneath the hood. I prefer one line with "import std.windows.windows;" to five cryptic lines that make it easy for me to mess up something.
Exactly. Or parhaps. module std.d.windows; import std.c.windows; extern (C) void gc_init(); extern (C) void gc_term(); extern (C) void _minit(); extern (C) void _moduleCtor(); extern (C) void _moduleUnitTests();
Jan 14 2004
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
"J Anderson" <REMOVEanderson badmama.com.au> wrote in message
news:bu4ne6$2t0a$1 digitaldaemon.com...
 J C Calvarese wrote:

 J Anderson wrote:

 Walter wrote:

 "imr1984" <imr1984_member pathlink.com> wrote in message
 If so why cant they be put into the windows.d import file?
I want to keep windows.d an analogue of windows.h
Why no have a dwindows (or something), which imports all the related stuff for windows?
Are you thinking of something like this? // ----------------------------------- // module std.windows.windows; extern (C) void gc_init(); extern (C) void gc_term(); extern (C) void _minit(); extern (C) void _moduleCtor(); extern (C) void _moduleUnitTests(); // ----------------------------------- // Seems like a good idea to me. I like to keep the mysterious stuff underneath the hood. I prefer one line with "import std.windows.windows;" to five cryptic lines that make it easy for me to mess up something.
Exactly. Or parhaps. module std.d.windows; import std.c.windows; extern (C) void gc_init(); extern (C) void gc_term(); extern (C) void _minit(); extern (C) void _moduleCtor(); extern (C) void _moduleUnitTests();
Why has nobody suggested: extern (C) { void gc_init(); void gc_term(); void _minit(); void _moduleCtor(); void _moduleUnitTests(); } ? It seems C should allow something like this: void gc_init(), gc_term(), _minit(), _moduleCtor(),_moduleUnitTests(); But I don't think it does. ? Sean
Jan 15 2004