VC2005 基本语法 问题

来源:百度知道 编辑:UC知道 时间:2024/05/11 15:05:08
在VC6 好用的代码 怎么在 2005里 报错呢?
原码:
char ch1[10],ch2[20],ch3[20];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
报错:
错误 1 error C2664: “int CWnd::GetWindowTextW(LPTSTR,int) const”: 不能将参数 1 从“char [10]”转换为“LPTSTR” f:\net\mybole\mybole\testdlg.cpp 70

不解之处: LPTSTR 到底是什么呢? 我用CString 的类型 和它也 匹配不上
到底 用什么类型的 参数呢 ??

LPTSTR是这样的定义的:

#ifdef _UNICODE
typedef wchar * LPTSTR;
#else
typedef char * LPTSTR;

知道了LPTSTR就好办了。
TCHAR ch1[10],ch2[10]........

.....GetWindowsText(ch1,10).......

应该可以的吧。。。

实在不行就这样好了
TCHAR ch1[10],ch2[20],ch3[20];

或者强制类型转换一下
(LPTSTR)ch1

强制转换试试..
GetWindowText((LPTSTR)ch1,10);
VC里面,一般字符串类型的参数都是这个类型
比如说AfxMessagebox函数

1)强制转化
GetDlgItem(IDC_EDIT1)->GetWindowText(((LPTSTR)ch1,9);
//字符串包括\0,所以最多能读9个

2)用CString,因如果读到的字符串如果长度大于9会读不全

CString sTxt = _T("") ;
GetDlgItemText( IDC_EDIT1 , sTxt ) ;