Sunday, August 20, 2006

Check SafeMode

How do you check wether a system is in safe mode or not .
Check out the Api GetSytemMetrics(SM_CLEANBOOT)its return value of 0 means its in normal mode or else its in safe mode or in cleanboot.

NOTE:- This is needed because in safemode most of the services are stoped and maybe your app cant move forward without some services .
The services that are runing can be checked by typing msconfig in the run command .

Namespace a Real Boon

Sometimes it hapens that we have to use the classes provided by third party people and when two classes have the same name it leads to class redefenition compile time error and we can't change the header files because they are the root of the lib implementaion or others.

So how do you resolve this :-
namespace FirstClass
#include "FirstClass.h"

namespace SecondClass
#include "SecondClass.h"
FirstClass::CMyclass and the SecondClass::CMyClass are refering to two different classes therby resolving the compile time error.
But maybe you have to look out for the linktime error :).

NOTE:- Any class you make it should be in the namespace .

Thursday, August 03, 2006

How to create a LPTSTR,

Well yesterday i ran into the problem of making LPTSTR ,and i found that LPTSTR is an TCHAR * so you can allocate in TCHAR . another way we use it in MFC was to use CString then use the GetBuffer and ReleaseBuffer,some times it hapens that the function needs an LPTSTR .
I fixed the problem by making a smart pointer of type BYTE and then passed this class to that function were it allocates and gives me back .it converts the BYTE to LPTSTR using the reinterpret_cast(arg);

Note :-
DWORD :- unsigned Long
WORD :- unsigned Short also known as an ATOM .
TCHAR :- converts itself into the unicode or mbcs according to the hash define in the settings .
_T()- this is macro short form of TEXT().
_tcs :- the one used in front of the string functions which can be used both for the
unicode ,Multibyte etc ,it will convert itself into _mbcs** or simple strcpy according to the define in settings .
While setting this we neeed to give an entry point also in mfc its always the _winmainstart**.( project settings + link tab + output (from the drop down))
while debugging if you need to see the unicode string you need to go to
Tool+OPtions+Debug TAB and then check the display unicode string.