Solved

DLL

Posted on 1998-05-13
6
929 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

752 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