LPWSTR tmpValue= new WCHAR[1024];
delete[] tmpValue;
Monday, September 14, 2009
Tuesday, September 8, 2009
Thursday, August 27, 2009
List - Iterator
for(list::iterator it=m_pptInitialSlideIDListNew.begin(); it!=m_pptInitialSlideIDListNew.end(); it++)
{
int iSlideIDCurrent = *it;
}
{
int iSlideIDCurrent = *it;
}
Tuesday, August 25, 2009
Thursday, August 13, 2009
doubleToString
SDBString_ptr SDBUtil::doubleToString(double number) {
char buffer[64];
sprintf(buffer, "%f", number);
//int count, count2;
for(char* p = buffer + strlen(buffer) - 1; p >= buffer; p--) {
if (*p == '0') {
*p = '\0';
} else {
if (*p == '.') {
*p = '\0';
}
break;
}
}
return new SDBString(buffer);
}
char buffer[64];
sprintf(buffer, "%f", number);
//int count, count2;
for(char* p = buffer + strlen(buffer) - 1; p >= buffer; p--) {
if (*p == '0') {
*p = '\0';
} else {
if (*p == '.') {
*p = '\0';
}
break;
}
}
return new SDBString(buffer);
}
stringToDouble
double SDBUtil::stringToDouble(char* data) {
int foundDot = 0;
for(char* p = data; *p; p++) {
if (isdigit(*p)) {
continue;
} else if (*p == '.') {
if (foundDot) {
throw strdup("Input wrong float");
} else {
foundDot = 1;
}
} else {
throw strdup("Input wrong float");
}
}
if (!foundDot) {
throw strdup("Input wrong float");
}
return atof(data);
}
int foundDot = 0;
for(char* p = data; *p; p++) {
if (isdigit(*p)) {
continue;
} else if (*p == '.') {
if (foundDot) {
throw strdup("Input wrong float");
} else {
foundDot = 1;
}
} else {
throw strdup("Input wrong float");
}
}
if (!foundDot) {
throw strdup("Input wrong float");
}
return atof(data);
}
stringToLong
long SDBUtil::stringToLong(char* data) {
for(char* p = data; *p; p++) {
if (!isdigit(*p)) {
throw strdup("Input wrong integer");
}
}
return atol(data);
}
for(char* p = data; *p; p++) {
if (!isdigit(*p)) {
throw strdup("Input wrong integer");
}
}
return atol(data);
}
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 ++;
}
{
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 ;
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()));
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();
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;
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;
//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;
Subscribe to:
Posts (Atom)