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;
}
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.
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.
Write or paste your answer into the text area below. When you are done, click the Submit button to submit your answer.