Writing a Win32 DLL in VC++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 12
Reputation: MitchellH is an unknown quantity at this point 
Solved Threads: 1
MitchellH MitchellH is offline Offline
Newbie Poster

Writing a Win32 DLL in VC++

 
0
  #1
Nov 26th, 2004
Im learning to write a DLL in Win32 C++ and I've found that its pretty straightforward I just have a few questions:

1.) Do I have to have a DllMain function?
2.) Why do some functions look like this:
  1. void _stdCall bla()
  2. {
  3. ...
  4. }

And some look like this:

  1. _declspec (dllexport) void bla()
  2. {
  3. ...
  4. }

What are the differences?

Thank you.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 4
Reputation: neuronco is an unknown quantity at this point 
Solved Threads: 0
neuronco neuronco is offline Offline
Newbie Poster

Re: Writing a Win32 DLL in VC++

 
0
  #2
Nov 26th, 2004
You can have a DLL without DllMain function. Its purpose is for Windows to notify your DLL of various events that might be of interest to it, e.g. whenever another EXE or DLL loads it etc.

_declspec (dllexport) is a Microsoft specific extension for the compiler to tell it to export your function "bla", so that other DLLs and EXEs can link to it and use it. Other way to accompilsh the same is to use the DEF file and specify your exports there.

void _stdcall bla() is just a normal function visible to your DLL only. _stdcall is specifying standard (or PASCAL) calling convention (as opposed to _cdecl or C calling convention).
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 12
Reputation: MitchellH is an unknown quantity at this point 
Solved Threads: 1
MitchellH MitchellH is offline Offline
Newbie Poster

Re: Writing a Win32 DLL in VC++

 
0
  #3
Nov 26th, 2004
Ah, thanks. So if i specify _stdCall, then other programs can't use it? And if i use _declspec (dllexport) then other programs can use it? AND THEN if I just make it a function w/o either of those, and put it in a definition file, then its the same as doing _declspec (dllexport)?
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 4
Reputation: neuronco is an unknown quantity at this point 
Solved Threads: 0
neuronco neuronco is offline Offline
Newbie Poster

Re: Writing a Win32 DLL in VC++

 
0
  #4
Nov 30th, 2004
Originally Posted by MitchellH
Ah, thanks. So if i specify _stdCall, then other programs can't use it? And if i use _declspec (dllexport) then other programs can use it? AND THEN if I just make it a function w/o either of those, and put it in a definition file, then its the same as doing _declspec (dllexport)?
Yes to all. One note, _stdcall has nothing to do with exporting. It specifies the calling convention for your function.

_declspec (dllexport) void _stdcall foo(int a, int b); or
_declspec (dllexport) void _cdecl foo(int a, int b); or
_declspec (dllexport) void foo(int a, int b); - uses compiler default

You should check your compiler documentation for the explanation of calling conventions.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC