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就是乱码?怎么回事啊。
{
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就是乱码?怎么回事啊。
这个函数的实现呢?
你怎么给pbstrVal赋值的
*pbstrVal = T2BSTR("asasdas")
改为BSTR pbstrVal,不要用指针
{
char Name[]="今天";
BSTR m_bstrTmpValue;
const unsigned short *pBuf = (const unsigned short *)Name;
m_bstrTmpValue = ::SysAllocString(pBuf);
*pbstrVal = m_bstrTmpValue;
}
在idl中是怎样定义的?[propget, id(10), helpstring("method GetVersion")] HRESULT GetVersion([out,retval] BSTR *bstrVersion);