Solved

DLL

Posted on 1998-05-13
6
915 Views
Last Modified: 2013-12-03
WINDOWSer,

If I write a DLL in Visual C++ (not using MFC), must I need to use the DLLMain, LibMain or DLLEntryPoint ?
By the way, what are the differents between them and when will them be called ?

So, is it similiar to Main and WinMain ?

Andrew
0
Comment
Question by:andrewyu
  • 3
  • 2
6 Comments
 
LVL 23

Accepted Solution

by:
chensu earned 0 total points
Comment Utility
LibMain is for 16-bit DLLs. DllEntryPoint is a placeholder for the library-defined function name. Visual C++ uses DllMain as the entry-point function name.

WinMain is for Windows GUI applications and main is for Windows Console applications.
0
 

Author Comment

by:andrewyu
Comment Utility
By the way, must I need to use them ?
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
If you do not have some special initialization and cleanup to do, just write it as follows:

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    return TRUE;
}

0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
Chensu, you said that

>> DllEntryPoint is a placeholder for the library-defined function name

DllEntryPoint() is what Borland C++ DLLs use as attach/detach procedure (whatevery you want to call it).  DllMain() and DllEntryPoint() have the same functions, but are for different compilers.  They also have slightly different syntax.  

What's more, somehow no Borland C++ programers out there seem to use it to detach or somehow never seemd to notice a serious bug.  The procedure gets called twice to detach from a process.  This is in both BC 5.0 and builder 3.0.  It was never noticed until I reported it and it has not been fixed yet!

Andrew, if you are working with a borland compiler I'll post the borland syntax.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
nietod,

Actually, it is not said by me. For your information, the following content is copied from the Platform SDK documentation.

DllEntryPoint
The DllEntryPoint function is an optional method of entry into a dynamic-link library (DLL). If the function is used, it is called by the system when processes and threads are initialized and terminated, or upon calls to the LoadLibrary and FreeLibrary functions.

DllEntryPoint is a placeholder for the library-defined function name. Many samples in the SDK use DllMain as the entry-point function name. You must specify the actual name you use when you build your DLL. For more information, see the documentation included with your development tools.

BOOL WINAPI DllEntryPoint(
  HINSTANCE hinstDLL,  // handle to DLL module
  DWORD fdwReason,     // reason for calling function
  LPVOID lpvReserved   // reserved
);

0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Great more confussion.  But you should realize now that if somone uses the name DllEntryPoint()  they may be working under Borland.  And Borland does not seem to provide a way to change the name.  (I compile under poth and would like to th use the same procedure under both.)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now