Basic COM   «Prev  Next»

Debug DllCanUnloadNow - Exercise

Debug DllCanUnloadNow

Objective: Find a bug in DllCanUnloadNow.

Instructions

Find the bug in the following code and explain what will happen as a result of the bug.
//Global Reference Counters
ULONG g_server_locks = 0;
ULONG g_objcnt = 0;

STDAPI DllCanUnloadNow() {
   if (g_server_locks == 0 || g_objcnt == 0)   
         return TRUE;
   return FALSE;
}

DllCanUnloadNow function

Determines whether the DLL that implements this function is in use. If not, the caller can unload the DLL from memory. OLE does not provide this function. DLLs that support the OLE Component Object Model (COM) should implement and export DllCanUnloadNow.

HRESULT DllCanUnloadNow();

Return value: If the function succeeds, the return value is S_OK. Otherwise, it is S_FALSE.

Notes to Callers

You should not have to call DllCanUnloadNow directly. OLE calls it only through a call to the CoFreeUnusedLibraries function. When it returns S_OK, CoFreeUnusedLibraries frees the DLL.

Exercise scoring


This exercise is worth 10 points. There is no partial credit given.

Exercise submission

Write or paste your answer into the text area below. When you are done, click the Submit button to submit your answer.