சனி, 20 பிப்ரவரி, 2010

What Is CMutex ?

What Is CMutex ?

An object of class CMutex represents a “mutex” — a synchronization object that allows one thread mutually exclusive access to a resource. Mutexes are useful when only one thread at a time can be allowed to modify data or some other controlled resource. For example, adding nodes to a linked list is a process that should only be allowed by one thread at a time. By using a CMutex object to control the linked list, only one thread at a time can gain access to the list.

To use a CMutex object, construct the CMutex object when it is needed. Specify the name of the mutex you wish to wait on, and that your application should initially own it. You can then access the mutex when the constructor returns. Call CSyncObject::Unlock when you are done accessing the controlled resource.

What is the difference between ASSERT and VERIFY?

The main difference between ASSERT and VERIFY is when you compile the release build of the program.

ASSERT will not be present in the release build version of the executables/dlls, and its expression that would have been evaluated will be deleted.

VERIFY will be present in the release build version of the executables/dlls but its expression that would have been evaluated will be left intact


what is the use of AFX_MANAGE_STATE ?

By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope.

If all your resources lies in the single DLL you can even change the default handle to the DLL handle with the help of AfxSetResourceHandle function.

கருத்துகள் இல்லை:

கருத்துரையிடுக