| | |
Writing a Win32 DLL in VC++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2004
Posts: 12
Reputation:
Solved Threads: 1
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:
And some look like this:
What are the differences?
Thank you.
I just have a few questions:1.) Do I have to have a DllMain function?
2.) Why do some functions look like this:
C++ Syntax (Toggle Plain Text)
void _stdCall bla() { ... }
And some look like this:
C++ Syntax (Toggle Plain Text)
_declspec (dllexport) void bla() { ... }
What are the differences?
Thank you.
•
•
Join Date: Nov 2004
Posts: 4
Reputation:
Solved Threads: 0
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).
_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).
•
•
Join Date: Nov 2004
Posts: 4
Reputation:
Solved Threads: 0
•
•
•
•
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)?
_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.
![]() |
Similar Threads
- Problem in loading VC++ Win32 dll in C# (C++)
- win32 window painting fails (C++)
- Dll's and problems with them (C++)
- static and dynamic Dll (C++)
- 9 Popups, HJT Included (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: C++ strcmp
- Next Thread: Problem with validation in c
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





