以前有很多这种帖子,你搜索一下,如:(1) 把CString类型的数据赋值给LPTSTR类型的变量 如:CString str("demo"); LPTSTR lpstr=(LPTSTR)(LPCTSTR)str; (2) 将int转化为LPTSTR或了LPCTSTR型 方法1: int i = 100; char buf[20]; sprintf(buf,"%d",i); 方法2: int i = 100; CString s; s.format("%d",i); 方法3: int i = 100; char buf[20]; itoa( i, buf, 10 ); (3) 将CTime的类型转换成CString的类型 CString str; CTime time; time = CTime::GetCurrentTime(); str=time.Format("%Y年%m月%d日%H时%M分%秒"); (4) 将_variant_t类型转化为CTime类型或是别的类型 witch(variant->vt) { case VT_ERROR:{ strcpy(szValue,"ERROR"); break;} case VT_I2:{ wsprintf(szValue,"%d",variant->iVal); break;} case VT_I4:{ wsprintf(szValue,"%d",variant->iVal); break;} case VT_R4:{ wsprintf(szValue,"%f",variant->fltVal); break;} case VT_R8:{ wsprintf(szValue,"%f",variant->dblVal); break;} case VT_BSTR: strcpy(szValue,(char *)variant->bstrVal); break; case VT_CY:{ COleCurrency c(varValue); CString s=c.Format(); s+=" 元"; strcpy(szValue,s.GetBuffer(s.GetLength())); s.ReleaseBuffer(); break;} case VT_DATE:{ COleDateTime t(variant->date); CString s=t.Format("%Y年%m月%d日"); strcpy(szValue,s.GetBuffer(s.GetLength())); s.ReleaseBuffer(); break;} case VT_BOOL:{ if(variant->boolVal) strcpy(szValue,"TRUE"); else strcpy(szValue,"FALSE"); break;} case VT_UI1:{ switch(variant->bVal) { case 1: strcpy(szValue,"半新"); break; case 2: strcpy(szValue,"旧"); break; case 3: strcpy(szValue,"报废"); break; default: strcpy(szValue,"新"); break; } break;} default:{ szValue[0]='\0'; break;} }
FileTime与SystemTime之间的转换有专门的API来实现,分别是SystemTimeToFileTime和FileTimeToSystemTime(这两个函数猜也应该猜到了吧:) )DWORD ----char int char* int *这些转换意义不是很明确。比如说DWORD->char*,你是想把DWORD的内容转成字符串呢,还是把DWORD看成一个地址,把它转成char* ?
如:CString str("demo");
LPTSTR lpstr=(LPTSTR)(LPCTSTR)str;
(2) 将int转化为LPTSTR或了LPCTSTR型
方法1: int i = 100;
char buf[20];
sprintf(buf,"%d",i);
方法2: int i = 100;
CString s;
s.format("%d",i);
方法3: int i = 100;
char buf[20];
itoa( i, buf, 10 );
(3) 将CTime的类型转换成CString的类型
CString str;
CTime time;
time = CTime::GetCurrentTime();
str=time.Format("%Y年%m月%d日%H时%M分%秒");
(4) 将_variant_t类型转化为CTime类型或是别的类型
witch(variant->vt)
{
case VT_ERROR:{
strcpy(szValue,"ERROR");
break;}
case VT_I2:{
wsprintf(szValue,"%d",variant->iVal);
break;}
case VT_I4:{
wsprintf(szValue,"%d",variant->iVal);
break;}
case VT_R4:{
wsprintf(szValue,"%f",variant->fltVal);
break;}
case VT_R8:{
wsprintf(szValue,"%f",variant->dblVal);
break;}
case VT_BSTR:
strcpy(szValue,(char *)variant->bstrVal);
break;
case VT_CY:{
COleCurrency c(varValue);
CString s=c.Format();
s+=" 元";
strcpy(szValue,s.GetBuffer(s.GetLength()));
s.ReleaseBuffer();
break;}
case VT_DATE:{
COleDateTime t(variant->date);
CString s=t.Format("%Y年%m月%d日");
strcpy(szValue,s.GetBuffer(s.GetLength()));
s.ReleaseBuffer();
break;}
case VT_BOOL:{
if(variant->boolVal)
strcpy(szValue,"TRUE");
else
strcpy(szValue,"FALSE");
break;}
case VT_UI1:{
switch(variant->bVal)
{
case 1: strcpy(szValue,"半新"); break;
case 2: strcpy(szValue,"旧"); break;
case 3: strcpy(szValue,"报废"); break;
default: strcpy(szValue,"新"); break;
}
break;}
default:{
szValue[0]='\0';
break;}
}
http://www.csdn.net/Develop/Read_Article.asp?Id=12365