Posts

Showing posts from 2004

#define variable arguments

Since #define does not take variable arguments you have to work around using function pointers.


void __format_out(const char* fmt, ...);

typedef void (*ptr2Fn) (const char* fmt, ...) ;

ptr2Fn _storeLine(int nSeverity,int lineNumber,char* fileName);

#define CTRACE _storeLine(40,__LINE__,__FILE__)

-----------------------
ptr2Fn _storeLine(int nPSeverity,int nPlineNumber,char* szPfileName)
{

nSeverity = nPSeverity;
nlineNumber=nPlineNumber;
szfileName = (char*)szPfileName;

return __format_out;
}
-----------------------
inline void __format_out(const char * fmt, ...)
{

CString ___str;
va_list marker;
va_start(marker, fmt);
USES_CONVERSION;
___str.FormatV(A2T(fmt), marker);
va_end(marker);


}

TRACE("nUMBER IS %d",223);

vba code for iterating through colums

Private Sub CommandButton1_Click()
CalculateAndDispalyDifference
End Sub

Sub CalculateAndDispalyDifference()
Dim t1, t2 As Date

For counter = 2 To 91
t1 = Worksheets("Sheet1").Cells(counter, 4).Value
t2 = Worksheets("Sheet1").Cells(counter + 1, 4).Value
If t2 > t1 Then
Worksheets("Sheet1").Cells(counter, 6).Value = t2 - t1
Else
Worksheets("Sheet1").Cells(counter, 6).Value = t1 - t2
End If
counter = counter + 1
Next counter

End Sub

VBA xode snippet for iterating through colums

Private Sub CommandButton1_Click()
CalculateAndDispalyDifference
End Sub

Sub CalculateAndDispalyDifference()
Dim t1, t2 As Date

For counter = 2 To 91
t1 = Worksheets("Sheet1").Cells(counter, 2).Value //.Cells(row,column)
t2 = Worksheets("Sheet1").Cells(counter, 4).Value
If t2 > t1 Then
Worksheets("Sheet1").Cells(counter, 5).Value = t2 - t1
Else
Worksheets("Sheet1").Cells(counter, 5).Value = t1 - t2
End If

Next counter

End Sub

wcstok,strtok memory corruption

CString mystring("ob_jw_ay");

CString anotherstring ;

anotherstring =mystring;//memory corruption!!!

TCHAR* string = (TCHAR*)(LPCTSTR)mystring;
TCHAR seps[] = "_";
TCHAR* token;


token = strtok( string, seps );

while( token != NULL )
token = strtok( NULL, seps );

//Now both strings will be changed.Because both CString::m_pchData are pointing to the same memory and strok/wcstok changes it. If you want 'anotherstring' to remain unchanged do
anotherstring +=mystring;

Structured Exception Handling

http://www.microsoft.com/msj/0197/Exception/Exception.aspx

http://www.microsoft.com/msj/0898/bugslayer0898.aspx

http://groups.google.co.in/groups?hl=en&lr=&ie=UTF-8&selm=Xns94A2C525A6E9EnospamJochenKalmbach%40207.46.248.16&rnum=2

vtable layout and lookup

struct cA ;

struct A_vtbl
{
void (__stdcall* pfn_mem_fun)( struct cA* this, int v ) ;
void (__stdcall* pfn_mem_fun2)( const struct cA* this ) ;
void (__stdcall* pfn_mem_fun3)( struct cA* this ) ;
void (__stdcall* pfn_destructor)( struct cA* this ) ;
};

struct cA
{
struct A_vtbl* vptr ;
char c1 ;
int i ;
char c2[1] ;
};

void cfun( struct cA* pa )
{
//pa->mem_fun2() ;
pa->vptr->pfn_mem_fun2(pa) ;
//pa->mem_fun(100) ;
pa->vptr->pfn_mem_fun(pa,100);
}

type safety importance link

From -
http://www.securingjava.com/chapter-two/chapter-two-10.html

Why Type Safety Matters
Type safety is the most essential element of Java's security. To understand why, consider the following slightly contrived example. A calendar-management applet defines a class called Alarm. This class is represented in memory as shown in Figure 2.10. Alarm defines an operation turnOn, which sets the first field to true. The Java runtime library defines another class called Applet, whose memory layout is also shown in Figure 2.10. Note that the first field of Applet is fileAccessAllowed, which determines whether the applet is allowed access to files on the hard disk.
Figure 2.10 Type safety provides an important foundation for the Java security model.In this figure, two classes, Alarm and Applet, each include a number of fields. Setting the first field in these classes to "true" is not equivalent. Type safety checks ensure that any object a method may try to manipulate is of the pro…

windbg commands

A good link for windbg commands ref

http://perso.b2b2c.ca/makigor/files/WinDBG.rtf