小弟正在使用VC,用OLEDB方式联结SQL SERVER,在获得SQL返回的错误信息时遇到了一些问题。我是这样取得错误信息的: HRESULT hr = errInfo.GetErrorRecords(pUnk,iid, &ulRecords); if (FAILED(hr) || hr == S_FALSE || ulRecords == 0) { ShowError(_T("NOSPECIFIED_SOURCE")); return ; } else { LCID lcid = GetUserDefaultLCID(); for (ULONG l=0; l<ulRecords; l++) { // Get the error information from the source struct MYERRORINFO* pInfo = new MYERRORINFO; hr = errInfo.GetAllErrorInfo(l, lcid, &pInfo->bstrDescription, &pInfo->bstrSource, &pInfo->guid, &pInfo->dwHelpContext, &pInfo->bstrHelpFile); if (FAILED(hr)) { delete pInfo; continue; }
strError += CString(pInfo->bstrDescription) + "\n"; delete pInfo; } } 但发现只有在主线程中运行时,才能获得错误信息,否则都无法获得,有大侠知道其中的原因吗