Sunday, October 01, 2006
Wednesday, September 27, 2006
Hi Guys
Sorry for the big delay , i was really busy with work will try to put some intresting things shortly.
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 .
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 .
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.
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
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.
Sunday, July 30, 2006
mystery behind USES_CONVERSION
Well this guy _alloca allocates memory from the stack and not from the heap,basically used by the USES_CONVERSION macro in the ATL ,leading to the cause of stack-overflow ,wen used inside a loop .This automatically gets freed when it goes out of the function scope .
And the default size of the stack in VC6 is 1MB .
ATL7.0 doesn't have this problem.
And the default size of the stack in VC6 is 1MB .
ATL7.0 doesn't have this problem.
Wednesday, July 26, 2006
Scope of namespace
Consider this :-
namespace PPP
{
CMyclass {
....
};
int iPPP;
}
int CMytest::ExampleNameSpace( PPP:: CMyclass &oTest, int p)
{
return iPPP;
}
it takes iPPP from the namespace of the PPP , firstchecks in the scope of CMytest and then in the scope of the std <\b> and then in the scope of the function argument scope .
Popularly known as namelook up rule
namespace PPP
{
CMyclass {
....
};
int iPPP;
}
int CMytest::ExampleNameSpace( PPP:: CMyclass &oTest, int p)
{
return iPPP;
}
it takes iPPP from the namespace of the PPP , firstchecks in the scope of CMytest and then in the scope of the std <\b> and then in the scope of the function argument scope .
Popularly known as namelook up rule
Tuesday, July 25, 2006
How to call the constructors in vector
CMyClass(int ,int):- is the default constructor
std::vector <CMyClass> oTest(2,CMyClass(2,3));
The above line will create 2 objects of type CMyClass and calls the constructor with the params 2 and 3.
std::vector <
The above line will create 2 objects of type CMyClass and calls the constructor with the params 2 and 3.
Sunday, July 16, 2006
Use AfxSetWindowText
Internally this does an GetWindowText and sees wether the text are different and updates only if they are different ,therby saving un-necessary updates,
How easy to delete the linked list in c++
typedef struct _tagLinkedList
{
_tagLinkedList *pNextLink;
int m_iData;
_tagLinkedList()
{
pNextLink = NULL;
}
~_tagLinkedList()
{
if (pNextLink )
delete pNextLink;
pNextLink = NULL
}
}sLinkedList;
{
_tagLinkedList *pNextLink;
int m_iData;
_tagLinkedList()
{
pNextLink = NULL;
}
~_tagLinkedList()
{
if (pNextLink )
delete pNextLink;
pNextLink = NULL
}
}sLinkedList;
Saturday, July 08, 2006
Complete list of pseudoregisters
Description
@ERR
Last error value; the same value returned by the GetLastError() API function
@TIB
Thread information block for the current thread; necessary because the debugger doesn't handle the "FS:0" format
@CLK
Undocumented clock register; usable only in the Watch window
@EAX, @EBX, @ECX, @EDX, @ESI, @EDI, @EIP, @ESP, @EBP, @EFL
Intel CPU registers
@CS, @DS, @ES, @SS, @FS, @GS
Intel CPU segment registers
@ST0, @ST1, @ST2, @ST3, @ST4, @ST5, @ST6, @ST7
Intel CPU floating-point registers
[Table from "Debugging Applications" by John Robbins]
@ERR
Last error value; the same value returned by the GetLastError() API function
@TIB
Thread information block for the current thread; necessary because the debugger doesn't handle the "FS:0" format
@CLK
Undocumented clock register; usable only in the Watch window
@EAX, @EBX, @ECX, @EDX, @ESI, @EDI, @EIP, @ESP, @EBP, @EFL
Intel CPU registers
@CS, @DS, @ES, @SS, @FS, @GS
Intel CPU segment registers
@ST0, @ST1, @ST2, @ST3, @ST4, @ST5, @ST6, @ST7
Intel CPU floating-point registers
[Table from "Debugging Applications" by John Robbins]
Thursday, July 06, 2006
System Messages
Prefix Message category
ABM Application desktop toolbar
BM Button control
CB Combo box control
CBEM Extended combo box control
CDM Common dialog box
DBT Device
DL Drag list box
DM Default push button control
DTM Date and time picker control
EM Edit control
HDM Header control
HKM Hot key control
IPM IP address control
LB List box control
LVM List view control
MCM Month calendar control
PBM Progress bar
PGM Pager control
PSM Property sheet
RB Rebar control
SB Status bar window
SBM Scroll bar control
STM Static control
TB Toolbar
TBM Trackbar
TCM Tab control
TTM Tooltip control
TVM Tree-view control
UDM Up-down control
WM General window
Taken From MSDN
ABM Application desktop toolbar
BM Button control
CB Combo box control
CBEM Extended combo box control
CDM Common dialog box
DBT Device
DL Drag list box
DM Default push button control
DTM Date and time picker control
EM Edit control
HDM Header control
HKM Hot key control
IPM IP address control
LB List box control
LVM List view control
MCM Month calendar control
PBM Progress bar
PGM Pager control
PSM Property sheet
RB Rebar control
SB Status bar window
SBM Scroll bar control
STM Static control
TB Toolbar
TBM Trackbar
TCM Tab control
TTM Tooltip control
TVM Tree-view control
UDM Up-down control
WM General window
Taken From MSDN
Wednesday, July 05, 2006
STL warning
Hi , you all might have faced the STL Junk warning to change them to meaningful one you can download the following perl Script and it will convert them to meaningful details .
you can have it from :-
http://www.bdsoft.com/tools/stlfilt.html
you can have it from :-
http://www.bdsoft.com/tools/stlfilt.html
Tuesday, July 04, 2006
Re :Recursion
Hi Folks you might have read my previous mail on recursion ,so here iam presenting one more great way of doing it using class template :-
template <"int N">
class Fact {
public:
enum { value = N * Fact::value };
};
//Template specialization
class Fact<1> {
public:
enum { value = 1 };
};
make a obj of Factorial and then retreive the value ,the good thing is no function call is made only expansion at runtime is hapening and its an crisp code ,
Template is very powerful in scientific computing .
You can expect more intresting posts on template shortly.
template
class Fact {
public:
enum { value = N * Fact
};
//Template specialization
class Fact<1> {
public:
enum { value = 1 };
};
make a obj of Factorial and then retreive the value ,the good thing is no function call is made only expansion at runtime is hapening and its an crisp code ,
Template is very powerful in scientific computing .
You can expect more intresting posts on template shortly.
Monday, July 03, 2006
Bugs in VC6.0
Sometimes our work gets stuck due to some bugs in vc6.0 and here you can find some of the bug list :-
http://support.microsoft.com/kb/834001/
http://support.microsoft.com/kb/834001/
Sunday, July 02, 2006
Imp Values in Debugger
Value Usage
0xCDCDCDCD Allocated in heap, but not initialized
0xDDDDDDDD Released heap memory.
0xFDFDFDFD "NoMansLand" fences automatically placed at boundary of heap memory. Should never be overwritten. If you do overwrite one, you're probably walking off the end of an array.
0xCCCCCCCC Allocated on stack, but not initialized
0xCDCDCDCD Allocated in heap, but not initialized
0xDDDDDDDD Released heap memory.
0xFDFDFDFD "NoMansLand" fences automatically placed at boundary of heap memory. Should never be overwritten. If you do overwrite one, you're probably walking off the end of an array.
0xCCCCCCCC Allocated on stack, but not initialized
Thursday, June 29, 2006
Recursion
yes recursion ,thinking iam mad iam not .
Recussion are of two types:-
1.General Recursion .
2.TailEnd Recursion .
1.General Recursion :- This is the one in which the whole part of the function needs to be activate till the last function call:
// For the Factorial
int Generalrecusrion(int iVal)
{
if (iVal==0)
return 0;
else if (iVal==1) return 1;
else return iVal * Generalrecusrion(iVal-1);
}
2. Tail Recursion :-
The function will not be active bcoz the function call to the next recursion will take off and terminate the prev Function .
// For the Factorial
int Tailrecursion(int n, int a )
{
if (n < 0)
return 0;
else if (n == 0)
return 1;
else if (n == 1)
return a;
else return Tailrecursion(n - 1, n * a);
}
// For the harmonic Progression// 1 + 1/2 + 1/3 + 1/4+...
float Harmonic(float n ,float iii )
{
if (n < 0) return 0;
else if (n == 0) return 1;
else if (n == 1) return iii;
else {
float fVal = iii + float (1/n );
return Harmonic(n - 1, fVal );
}
}
Even the compiler will help us in optimizing the following code to more level.
Recussion are of two types:-
1.General Recursion .
2.TailEnd Recursion .
1.General Recursion :- This is the one in which the whole part of the function needs to be activate till the last function call:
// For the Factorial
int Generalrecusrion(int iVal)
{
if (iVal==0)
return 0;
else if (iVal==1) return 1;
else return iVal * Generalrecusrion(iVal-1);
}
2. Tail Recursion :-
The function will not be active bcoz the function call to the next recursion will take off and terminate the prev Function .
// For the Factorial
int Tailrecursion(int n, int a )
{
if (n < 0)
return 0;
else if (n == 0)
return 1;
else if (n == 1)
return a;
else return Tailrecursion(n - 1, n * a);
}
// For the harmonic Progression// 1 + 1/2 + 1/3 + 1/4+...
float Harmonic(float n ,float iii )
{
if (n < 0) return 0;
else if (n == 0) return 1;
else if (n == 1) return iii;
else {
float fVal = iii + float (1/n );
return Harmonic(n - 1, fVal );
}
}
Even the compiler will help us in optimizing the following code to more level.
Monday, June 26, 2006
Friday, June 23, 2006
Bad Week
This whole week was bad for me lets see wats there for me in this last day of the week .
I feel iam geting saturated , i need to move on ,YES i need to move on ,HUMM how i wish i knew how i could .
I feel iam geting saturated , i need to move on ,YES i need to move on ,HUMM how i wish i knew how i could .
Wednesday, June 21, 2006
Calling delete this in the destructor
When you call delete this in the destructor of the coressponding class it goes into an recursion and an stack overflow hapens .
RULE:-
new :- calls the constructor
delete :- calls the destructor .
malloc,calloc, realloc :- nothing hapens only alloacation hapens
replacement new :- has to be used to call the coresponding constructor of the class allocated through malloc.
RULE:-
new :- calls the constructor
delete :- calls the destructor .
malloc,calloc, realloc :- nothing hapens only alloacation hapens
replacement new :- has to be used to call the coresponding constructor of the class allocated through malloc.
Subscribe to:
Posts (Atom)
