Solved

DLL

Posted on 1998-05-13
6
918 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
ID: 1401414
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
ID: 1401415
By the way, must I need to use them ?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1401416
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 1401417
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
ID: 1401418
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
ID: 1401419
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

867 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

12 Experts available now in Live!

Get 1:1 Help Now