1. COM相关接口函数实现, 接口getStepArray typedef struct tagStepInfo{ int iDigit; CComBSTR bstrText; }SETPINFO; STDMETHODIMP CXXX::getStepArray(VARIANT *pVariant) { // TODO: Add your implementation code here SETPINFO stSInfo; PackStep(pVariant, stSInfo); return S_OK; } //打包SETPINFO到Variant变量; HRESULT CXXXXX::PackStep(VARIANT *pVariant, SETPINFO stSInfo) { long i = 0; HRESULT hr = S_OK; SAFEARRAY* pArray = NULL; VARIANT var; pArray = SafeArrayCreateVector(VT_VARIANT, 0, 2); if (pArray == NULL){ return -1; } VariantInit(&var); var.vt = VT_I4; var.lVal = stSInfo.iDigit; //转换为BSTR字符串类型 ::VariantChangeType(&var, &var, 0, VT_BSTR); hr = SafeArrayPutElement(pArray, &i, &var); if (FAILED(hr)){ SafeArrayDestroy( pArray ); return -1; } ++i; var.bstrVal = stSInfo.bstrText.Copy(); hr = SafeArrayPutElement(pArray, &i, &var); if (FAILED(hr)){ SafeArrayDestroy( pArray ); return -1; } ++i; VariantInit(pVariant); VariantClear(&var); pVariant ->vt = VT_ARRAY | VT_VARIANT; pVariant ->parray = pArray; return 0; } 2. html代码实现, 采用javascript调用COM接口获取到数组为VBArray,需要将其转换为JSArray <html> <body> <script language=javascript> if (document.AtlComId){ var vbArray = document.AtlComId.getStepArray(); var jsArray = vbArray.toArray(); alert(jsArray); } </script> <object classid="clsid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" id="AtlComId" width="100" height="100"> </object> </body> <html>