Thursday, July 30, 2009

for use

for(list::iterator it=m_listResizedCol.begin(); it!=m_listResizedCol.end(); it++)
{
double dWidth = *it;
if (count == i)
{
if (vWidth.dblVal <>dWidth)
{
VARIANT vAddress;
std::stringstream indexValue;
indexValue << i;
*strIndex += indexValue.str().c_str();
*strIndex += ",";

std::stringstream widthValue;
widthValue << vWidth.dblVal;
*strWidth += widthValue.str().c_str();
*strWidth += ",";

countResizeCol++;
}
break;
}
count ++;
}

Monday, July 6, 2009

Convert int to BSTR

char* tempStr = new char[1024];
sprintf(tempStr, "%d", endCol);//endCol is int
BSTR strEndCol = SysAllocString((BSTR)tempStr);

//free memory
delete [] tempStr ;

convert char to BSTR

string strValueTemp = split1;//split1 is char
BSTR address = SysAllocString(OAConvertToLPWSTR(strValueTemp.c_str()));

Friday, July 3, 2009

Convert BSTR to char

wstring strLimitedSheetsTemp = SysAllocString(LimitedSheets);//LimitedSheets is BSTR
char* charVal= new char[strLimitedSheetsTemp.length() + 1];
wsprintfA(charVal, "%S", strLimitedSheetsTemp.c_str());

//free memory
delete [] charVal;
strLimitedSheetsTemp.clear();

Cach chuoi voi while

//Lay tung sheet tu LimitedSheets="Sheet1*B:C,6:6?Sheet3*11:15"
bool checkStatus = false;

wstring strLimitedSheetsTemp = SysAllocString(LimitedSheets);
char* original = new char[strLimitedSheetsTemp.length() + 1];
wsprintfA(original, "%S", strLimitedSheetsTemp.c_str());

char *split1 = new char[1024];
int i = 0;
int j = 0;

while (original[i] != '\0')
{
if (original[i] == '?' || original[i] == '\0')
{
split1[j++] = '\0';

checkStatus = ExcelCheckLimitedCopyLevel2(split1, sheetName);
if (checkStatus) break;

delete [] split1;
split1 = new char[1024];
j=0;
}
else
{
split1[j++] = original[i];
}
i++;
}
if (original[i] == '\0')
{
split1[j++] = '\0';
checkStatus = ExcelCheckLimitedCopyLevel2(split1, sheetName);
}
//free memory
delete [] split1;

Su dung strtok in C++

bool checkStatus = false;

//wstring strSelAddrListTemp = SysAllocString(SelAddrList);
//char* charSelAddrList = new char[strSelAddrListTemp.length() + 1];
//wsprintfA(charSelAddrList, "%S", strSelAddrListTemp.c_str());
StringUtil *strSelAddrListTemp = new StringUtil();
*strSelAddrListTemp += ConvertBSTRToString(SelAddrList);

wstring strAddressTemp = SysAllocString(Address);
char* pch1 = new char[strAddressTemp.length() + 1];
wsprintfA(pch1, "%S", strAddressTemp.c_str());

char* pch;

//pch = strtok(charSelAddrList, ",");
pch = strtok((char*)strSelAddrListTemp ->data(), ",");

int position = 0;
while (pch != NULL)
{
if (stricmp(pch, pch1) == 0)
{
checkStatus = true;
break;
}
pch = strtok (NULL, ",");
position++;
}

//free memory
//delete charSelAddrList;
strSelAddrListTemp ->freeBuf();
delete pch1;

Khoi tao bien BSTR

BSTR value = SysAllocString(L"hello");