IClassFactory::LockServer
LockServer() function provides a way for a client to lock the server down in the memory, even if there are actually no active objects in the server.
Called by the client of a class object to keep a server open in memory, allowing instances to be created more quickly.
HRESULT LockServer( BOOL fLock );
Parameter
- fLock - [in] If TRUE, increments the lock count; if FALSE, decrements the lock count.
Return Values
This method supports the standard COM/DCOM return values E_FAIL, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following:
- S_OK - The specified object was either locked ( fLock = TRUE) or unlocked from memory ( fLock = FALSE).
Code without LockServer()
CoGetClassObject call get Factory Interface Factory->CreateInstance(Interface1); /* new allocation */ Interface1->DoOperation1() Interface1->DoOperation2() Interface1->Release();/* COM server unloaded */ Factory->CreateInstance(Interface2); /* new allocation */ Interface2->DoOperation1() Interface2->DoOperation2() Interface2->Release();/* COM server unloaded */ Factory->CreateInstance(Interface1); /* new allocation */ Interface1->DoOperation1() Interface1->DoOperation2() Interface1->Release();/* COM server unloaded */ Factory->CreateInstance(Interface2); /* new allocation */ Interface2->DoOperation1() Interface2->DoOperation2() Interface2->Release();/* COM server unloaded */
Code with LockServer()
CoGetClassObject call get Factory Interface Factory->LockServer(TRUE); Factory ->CreateInstance(Interface1); /* new allocation */ Interface1->DoOperation1() Interface1->DoOperation2() Interface1->Release(); /* COM object not unloaded */ Factory ->CreateInstance(Interface2); /* new allocation */ Interface2->DoOperation1() Interface2->DoOperation2() Interface2->Release();/* COM object not unloaded */ Factory ->CreateInstance(Interface1); /* reuse of object */ Interface1->DoOperation1() Interface1->DoOperation2() Interface1->Release();/* COM object not unloaded */ Factory ->CreateInstance(Interface2); /* reuse of object */ Interface2->DoOperation1() Interface2->DoOperation2() Interface2->Release();/* COM object not unloaded */ Factory->LockServer(FALSE); Factory->Release(); /* deallocate all objects and server unloaded */
About our authors: Team EQA
You have viewed 1 page out of 67. Your COM/DCOM learning is 0.00% complete. Login to check your learning progress.