EQuestionAnswers.com Computer/Electronics Questions and Answers
C, C++, VC++, COM/DCOM, DLL and more
#Login #Sign up  Facebook Twitter TGoogle+
 

#Previous question #Index of COM/DCOM Questions #Next question

Generic DLL entry point

In-proc COM DCOM module are implemented as dynamic link libraries. DllMain() is the generic DLL entry point. OLE/COM framework loads the DLL using CoLoadLibrary(). CoFreeLibrary/CoFreeAllLibraries is the function to unload the same library. Client application never call these functions directly. DllMain() will be called with DLL_PROCESS_ATTACH when a COM client process is attached. Again DllMain() will be called with DLL_PROCESS_DETACH once COM process exits.

/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
  if (dwReason == DLL_PROCESS_ATTACH) {
    /* Client process attached */
  } else if (dwReason == DLL_PROCESS_DETACH)
    /* Client process detached */
  return TRUE;
}

COM/DCOM entry and exit

There are two additional functions exported from COM DLL which are COM specific entry and exit point function. DllGetClassObject() is the function entry point for all the clients for getting a instance of the class object. DllCanUnloadNow() is the exit point function of an in-process server.

file: COMEntryExitExample.def
=======================================
LIBRARY      "COMEntryExitExample"

DESCRIPTION  'Proxy/Stub DLL'

EXPORTS
	DllGetClassObject       @1	PRIVATE
	DllCanUnloadNow         @2	PRIVATE
=======================================

DllGetClassObject

COM client retrieves the class object from a DLL object handler or object application. DllGetClassObject is not called directly by client application. However it called from COM/OLE framework through CoGetClassObject/CoCreateInstance functions. DllGetClassObject is a mandatory function to be exported from a in-proc DLL server.

STDAPI DllGetClassObject(
  REFCLSID rclsid,  //CLSID for the class object
  REFIID riid,      //Reference to the identifier of the interface
                    // that communicates with the class object
  LPVOID * ppv      //Address of output variable that receives the
                    // interface pointer requested in riid
);

Parameters

  • rclsid - [in] CLSID that will associate the correct data and code.
  • riid - [in] Reference to the identifier of the interface that the caller is to use to communicate with the class object. Usually, this is IID_IClassFactory (defined in the OLE headers as the interface identifier for IClassFactory).
  • ppv - [out] Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer. If an error occurs, the interface pointer is NULL.

Return Values

This function supports the standard return values E_INVALIDARG, E_OUTOFMEMORY and E_UNEXPECTED, as well as the following:

  • S_OK - The object was retrieved successfully.
  • CLASS_E_CLASSNOTAVAILABLE - The DLL does not support the class (object definition).

DllCanUnloadNow

Determines whether the DLL that implements this function is in use. If not, the caller can safely unload the DLL from memory. This function is not called directly by client application. COM/OLE framework calls this function while CoFreeUnusedLibraries/ CoFreeUnusedLibrariesEx are executed inside the framework. Once S_OK is returned from the function, CoFreeLibrary() will be called to unload the DLL from memory.

This is an optional function to be exported from COM DLL. If this function is not implemented or not exported then there is no way to check if the DLL can be unloaded. DLL will not be unloaded even if no objects are alive. This will be unloaded at the last when CoUninitialize() is called by client.

STDAPI DllCanUnloadNow();

Parameters

None

Return Values

  • S_OK - The DLL can be unloaded.
  • S_FALSE - The DLL cannot be unloaded now.

You have viewed 1 page out of 66. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.

 Vote 0

Similar topics related to this section

# COM DCOM Interview Questions and Answers :: ALL Interview .com
# COM DCOM - COM DCOM Interview Questions
# COM interview questions | TechInterviews
# COM Interview Questions - CodeProject
# Com Dcom Interview Questions - Com and Dcom in Asp Net
# ATL Interview Questions and Answers :: ALL Interview .com
# ActiveX Interview Questions and Answers :: ALL Interview .com

* #1 webmaster Mon 28 Apr/2014 20:09:05(GMT)  Like 0 Unlike 0

Dear Users,

We are pleased to inform you that a forum/blog has been incorporated with www.mybestnotes.co.in. You are welcomed to add your comments, requests, codes, solutions and feedback to it. Please login(if already a member) or signup(for free) to avail to this facility.

Regards,
Webmaster

Your message goes here:

Name:Guest
Email:anonymous@unknown.com
My Post:*
Secutiry Code: ******  *
Preview this compose before posting this in discussion forum.
 
Note:
  1. Use [Sxx] code to show smiles. Example [S02]
  2. Use [URL ], example [URL http://www.google.com/]
  3. To display code or un formatted text use [CODE] [/CODE]. Example: [CODE] printf("Hello world"); [/CODE]
 [S01]   [S02]   [S03]   [S04]   [S05]   [S06]   [S07]   [S08] 
 [S09]   [S10]   [S11]   [S12]   [S13]   [S14]   [S15]   [S16] 
 [S17]   [S18]   [S19]   [S20]   [S21]   [S22]   [S23]   [S24] 

Note: Only members are allowed, * fields are mandatory.