GetDlgItemText(hwnd,IDC_EDIT1,STR1,sizeof(STR1));
       temp=strlen(STR1);
为什么这么得不到STR1里字符串的长度?得到的是一个负值?怎么写才能得到?

解决方案 »

  1.   

    跟踪一下,断点设在temp=strlen(STR1)处.程序停下后,看看 STR1 是什么内容就知道了.
      

  2.   

    Debug下调试一下,你的STR1的数据对吗?
      

  3.   

    SRT1里内容正确啊。比如输入的是1234
    得到的
    STR1 0X0012fb70 "1234"
    temp -858993460
      

  4.   

    TCHAR STR1[19];
    int temp;
    GetDlgItemText(hwnd,IDC_EDIT1,STR1,sizeof(STR1));
    temp=strlen(STR1);
    我是这么写的。现在就是想得到输入的字符个数。。
      

  5.   

    你的STR1定义的是什么类型的?
    若是char*类型的话,应该是没问题呢
      

  6.   

    #define MAX_COUNT 19
    TCHAR STR1[MAX_COUNT];
    int temp;
    GetDlgItemText(hwnd,IDC_EDIT1,STR1,MAX_COUNT);
    temp=_tcslen(STR1);
      

  7.   

    新手还是不要用unicode了,将项目的类型改成多节字符集。
      

  8.   

    // unicode工程?
    _tcslen(STR1); //这样怎么样?
      

  9.   

    D:\cx\sfz2\MainDlg.cpp(38) : error C2065: '_tcslen' : undeclared identifier
      

  10.   


    const int MaxLen = 128;
    CString STR1;
    GetDlgItemText( IDC_EDIT1, STR1, MaxLen );
    int temp = STR1.GetLength();这个应该可以哦
      

  11.   

    用的是
    Microsoft Visual C++ 6.0

      

  12.   

    'wcslen' : cannot convert parameter 1 from 'char [19]' to 'const unsigned short *'
      

  13.   

    咦,我那方法应该可以啊,就是在MFC中调试通过的
    9楼高人写的是Unicode工程,好像要加什么头文件吧,呵呵这个不熟悉
      

  14.   


    请看一下你的声明的是TCHAR类型,strlen的原型是:size_t strlen( const char *string );
    TCHAR:
    typedef char          TCHAR;  
    For Unicode platforms, TCHAR is defined as synonymous with the WCHAR type. 
    所以,根据你的环境,用wcslen试试吧
      

  15.   

    'wcslen' : cannot convert parameter 1 from 'char [19]' to 'const unsigned short *'
    貌似还是搞不出来啊。我现在就想得到用户输入的字母或数字个数。谁能帮忙写个……
    我用的是vc 6.0
      

  16.   

    UINT GetDlgItemText(          HWND hDlg,
        int nIDDlgItem,
        LPTSTR lpString,
        int nMaxCount
    );
    If the function succeeds, the return value specifies the number of TCHARs copied to the buffer, not including the terminating NULL character.
      

  17.   

    难道这个不行?要不你就干脆在classwizard中定义IDC_EDIT1:m_edt1;
    然后在函数中:
    CString CxxxDlg::GetValue()
    {
      UpdateData(true);
      int temp = m_edt1.GetLength();
      return m_edt1;
    }
      

  18.   

    CString str1;
    GetDlgItemText(IDC_, str1);
    int temp = str.GetLength();
    //试试这个
      

  19.   

    额。不知道为什么。在Variable窗口里显示的temp是不正确的。但是通过MessageBox显示出来就正确了。……
      

  20.   

    哥们 UINT GetDlgItemText( HWND hDlg,
      int nIDDlgItem,
      LPTSTR lpString,
      int nMaxCount
    ); 返回值是不是就是你想要的的数据呢?