STDMETHODIMP CCodeCvtCo::GetValueByRowCol(int nRow, int nCol, BSTR *pbstrVal)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here
CStaticDataProcessor::Instance()->GetFieldValueOf(nRow, nCol, pbstrVal);
CComBSTR bs1 = (CComBSTR)*pbstrVal;
*pbstrVal = bs1.Copy();
// CString szRet = (CString)*pbstrVal;
// *pbstrVal = szRet.AllocSysString(); return S_OK;
}以上代码试了好多种,在return S_OK的时候值从内存中看还是正常的,可是到C#或者asp中像如下方式调用时就显示乱码?请高手指教。       private void button1_Click(object sender, EventArgs e)
        {
            CONVERTINTERFACELib.CodeCvtCoClass cci = new CONVERTINTERFACELib.CodeCvtCoClass();
            int nRows = cci.GetMetadataByCode("000001");
            MessageBox.Show(nRows.ToString());            for (int i = 0; i < nRows; i++)
            {
                string strRet = cci.GetValueByRowCol(i, 0);
                MessageBox.Show(strRet);
            }
       }GetMetadataByCode这个接口返回整形是正确的,但是GetValueByRowCol接口返回的BSTR就是乱码?怎么回事啊。

解决方案 »

  1.   

    CStaticDataProcessor::Instance()->GetFieldValueOf(nRow, nCol, pbstrVal);
    这个函数的实现呢?
    你怎么给pbstrVal赋值的
      

  2.   

    通常是 
    *pbstrVal = T2BSTR("asasdas")
      

  3.   

    BSTR *pbstrVal
    改为BSTR pbstrVal,不要用指针
      

  4.   

    bool CStaticDataProcessor::GetFieldValueOf(int nRow, int nCol, BSTR *pbstrVal)
    {
    char Name[]="今天";
    BSTR m_bstrTmpValue;
    const unsigned short *pBuf = (const unsigned short *)Name;
    m_bstrTmpValue = ::SysAllocString(pBuf);
    *pbstrVal = m_bstrTmpValue;
    }
      

  5.   

    GetValueByRowCol函数的声明是怎样的?
    在idl中是怎样定义的?[propget, id(10), helpstring("method GetVersion")] HRESULT GetVersion([out,retval] BSTR *bstrVersion);