马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
问题:
ActiveX interfaces are accessible in C++ through the COM 'wrappers' as the doc
sample, AsdkMfcComSamps. When I used IAcadLayout::GetPlotDeviceNames(), it
returns a VARIANT type 8200. In this case, a string Array.
How do I access the elements in it? Attaching or creating SafeArrays of
COleSafeArray is successful and the upper and lower bounds are clear but I
cannot reach the data (strings).
解答:
This can be done by using some of the safe array global functions. The following
code sample demonstrates how to achieve this.
- bool GetStringListFromSafeArray(SAFEARRAY *psaItemTexts, CStringList &strNodes)
- {
- ASSERT (psaItemTexts);
- ULONG ulDims = SafeArrayGetDim(psaItemTexts);
- ASSERT (1 == ulDims);
- if (!psaItemTexts || 1 != ulDims)
- return false;
- // see if we are given more than one items
- long lLBound, lUBound; // note that dimension indices are one-based
- HRESULT hRes = SafeArrayGetUBound (psaItemTexts, 1, &lUBound);
- ASSERT (SUCCEEDED(hRes));
- if (FAILED (hRes))
- return false;
- hRes = SafeArrayGetLBound (psaItemTexts, 1, &lLBound);
- ASSERT (SUCCEEDED(hRes));
- if (FAILED (hRes))
- return false;
- // AcDcss the array
- BSTR *pabstrItemTexts = 0;
- hRes = ::SafeArrayAccessData (psaItemTexts, (void**)&pabstrItemTexts);
- ASSERT (SUCCEEDED (hRes));
- if (FAILED (hRes))
- return false;
- strNodes.RemoveAll ();
- USES_CONVERSION;
- for (long lName = lLBound; lName <= lUBound; lName ++)
- strNodes.AddTail (OLE2T (pabstrItemTexts [lName]));
- // release pointer returned by SafeArrayAcDcssData
- SafeArrayUnaccessData (psaItemTexts);
- return true;
- }
|