CString a;
BSTR b;
a="a";
b=(BSTR)"a";
if (a.AllocSysString()==b)
    printf("ok");
else
    printf("bad");//为什么程序运行后总出现bad,如何比较a和b呢?
//也就是如何输出ok呢?

解决方案 »

  1.   

    CString a;
    BSTR b;
    a="a";
    b=(BSTR)"a";
    CString st=a.AllocSysString();
    if (st==b)
        MessageBox("ok");
    else
        MessageBox("bad");
      

  2.   

    AllocSysString()地返回值不是BSTR吗?
      

  3.   

    BSTR 是指针类型吗?
    如果是的话,程序可以改为:
    CString a;
    BSTR b;
    a="a";
    b=(BSTR)"a";
    if (*a.AllocSysString()==*b)
        printf("ok");
    else
        printf("bad");这样就可以输出ok了。我的问题是:为什么BSTR是指针类型呢?怎么看出来呢?
      

  4.   

    #if defined(WIN32) && !defined(OLE2ANSI)
    typedef WCHAR OLECHAR;
    #else
    typedef char OLECHAR;
    #endiftypedef OLECHAR* BSTR;------------------from afxwin.h
      

  5.   

    我到是觉得还不如反过来比较,把bstr转成cstring的格式,用cstring本身带的成员函数来比较字符串