Tuesday, August 31, 2010

CArray Members

http://msdn.microsoft.com/en-us/library/7y7b8fx3.aspx

GetCount, GetSize, GetUpperBound seem to be all the same.

CString Methods at MSDN

http://msdn.microsoft.com/ja-jp/library/ms908314.aspx

Can use 'Find' to find a sub string in another string.


Copying a BSTR to a CString.

Note that the BSTR must be converted to a _bstr_t first.  If this is not done you only get the first character of the BSTR in the new CString.


BSTR GetBSTR() 
{     
_bstr_t bstr1(_T("This is the test string."));          
BSTR bstr;      bstr = bstr1.copy();      
   return bstr; 
}     
CComBSTR GetComBSTR() 
{     
CComBSTR bstr("This is the test string.");      
   return bstr; 
}   

void CVbsDlg::ShowBSTR(BSTR bstr) 
{     
_bstr_t bstrStart(bstr);           
CString s;      
s.Format(_T("%s"), (LPCTSTR)bstrStart);      AfxMessageBox(s);  
} 

COleDateTime:: Format

http://msdn.microsoft.com/en-us/library/bab3feb1(VS.80).aspx

The lowest resolution of the formating is in seconds.


DATE Description and Use


This is a 8-byte floating-point number.  Days are represented by whole number increments starting with 30 December 1899.

0.00 is 20 Dec 1899, midnight
-1.00 is 29 December 1899, midnight
5.50 is 4 January 1900, noon.



For comparing two dates:

if ((date2 - date1)  < FLT_EPSILON)
{
      printf("same date");
}

FLT_EPSILON is defined in the LIMITS.H include file for .NET. 

Defined in FLOAT.H for unmanaged code.



Friday, August 27, 2010

CArray CString Example


http://www.codersource.net/mfc/mfc-tutorials/carray.aspx

#include <Afxwin.h>
#include <Afxtempl.h>

void main()
{

CString l_strValue;
CArray<CString,CString> l_CArray;

for(int i=0;i< 20; i++)
{

  //Use the CString format function to create different values 
  l_strValue.Format("Value %d",i);
  //Add the formatted CString to CArray
  l_CArray.Add(l_strValue);

}

}


#include <Afxwin.h>
#include <Afxtempl.h>

void main()
{

CString l_strValue;
CArray<CString,CString> l_CArray;

for(int i=0;i< 20; i++)
{

  //Use the CString format function to create different values 
  l_strValue.Format("Value %d",i);
  //Add the formatted CString to CArray
  l_CArray.Add(l_strValue);

}

//This part takes care of accessing and printing the data from CArray
CString l_strGetVal;
for(i=0;i<=l_CArray.GetUpperBound();i++)
{
    l_strGetVal = l_CArray.GetAt(i);
    printf("%s\n",l_strGetVal);
}
 

}


 l_CArray.RemoveAll() //This will remove all the elements from CArray

           l_CArray.RemoveAt(10); //This will remove the 10th element from CArray