COM Component Returning An Array to VBScript
-
Hi All, In VC++ 6, I have created a simple COM component that contains a single method on a single interface that returns a 2 dimensional SafeArray (3 columsn, variable number of rows) wrapped by a VARIANT. I tested the component from a C++ test app and the data is returned in the Variant/SafeArray and can be extracted using conventional means, and all is well. This whole process took about 3 hours. I have spent the last 4 days trying to get the component to work when instantiated in ASP code (VBScript). Sorry for this long post but I want to include as much info as I can in hopes that some kind soul will help. The component was created with a single control (Simple Object). The function looks like this... STDMETHODIMP CSiteSearch::SearchHTM(BSTR searchPath, BSTR searchPhrase, VARIANT *pSearchResults) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) .................. Guts of function here to generate three CStringArrays (documentTypeArray,documentPathArray and documentContextArray) to be packed into the SafeArray and then wrapped by the Variant .................. // Now stuff the safe array and return the data DWORD numElements[2]; numElements[0] = 3; numElements[1] = documentTypeArray.GetSize(); COleSafeArray sa; sa.Create(VT_BSTR,2,numElements); long elementIndex[2]; BSTR bData; for (int row = 0; row < documentTypeArray.GetSize(); row++) { // Insert each column into the SafeArray elementIndex[0] = 0; elementIndex[1] = row; bData = _bstr_t(documentTypeArray.GetAt(row)); sa.PutElement(elementIndex,bData); elementIndex[0] = 1; elementIndex[1] = row; bData = _bstr_t(documentPathArray.GetAt(row)); sa.PutElement(elementIndex,bData); elementIndex[0] = 2; elementIndex[1] = row; bData = _bstr_t(documentContextArray.GetAt(row)); sa.PutElement(elementIndex,bData); } // Return the array in a variant CComVariant cVar; cVar.Attach(pSearchResults); cVar.Copy(sa); cVar.Detach(pSearchResults); } return S_OK; } This works fine when called from a VC++ dialog based, client app (importing the type library). The ASP/VBScript code that does not work looks like this... ' The creation of the control and the call of the method works without error Set searchControl = Server.CreateObject("WebSiteSearch.SiteSearch.1") theResults = searchControl.SearchHTM ( "C:\SomeFolderToSearch", searchPhrase )
-
Hi All, In VC++ 6, I have created a simple COM component that contains a single method on a single interface that returns a 2 dimensional SafeArray (3 columsn, variable number of rows) wrapped by a VARIANT. I tested the component from a C++ test app and the data is returned in the Variant/SafeArray and can be extracted using conventional means, and all is well. This whole process took about 3 hours. I have spent the last 4 days trying to get the component to work when instantiated in ASP code (VBScript). Sorry for this long post but I want to include as much info as I can in hopes that some kind soul will help. The component was created with a single control (Simple Object). The function looks like this... STDMETHODIMP CSiteSearch::SearchHTM(BSTR searchPath, BSTR searchPhrase, VARIANT *pSearchResults) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) .................. Guts of function here to generate three CStringArrays (documentTypeArray,documentPathArray and documentContextArray) to be packed into the SafeArray and then wrapped by the Variant .................. // Now stuff the safe array and return the data DWORD numElements[2]; numElements[0] = 3; numElements[1] = documentTypeArray.GetSize(); COleSafeArray sa; sa.Create(VT_BSTR,2,numElements); long elementIndex[2]; BSTR bData; for (int row = 0; row < documentTypeArray.GetSize(); row++) { // Insert each column into the SafeArray elementIndex[0] = 0; elementIndex[1] = row; bData = _bstr_t(documentTypeArray.GetAt(row)); sa.PutElement(elementIndex,bData); elementIndex[0] = 1; elementIndex[1] = row; bData = _bstr_t(documentPathArray.GetAt(row)); sa.PutElement(elementIndex,bData); elementIndex[0] = 2; elementIndex[1] = row; bData = _bstr_t(documentContextArray.GetAt(row)); sa.PutElement(elementIndex,bData); } // Return the array in a variant CComVariant cVar; cVar.Attach(pSearchResults); cVar.Copy(sa); cVar.Detach(pSearchResults); } return S_OK; } This works fine when called from a VC++ dialog based, client app (importing the type library). The ASP/VBScript code that does not work looks like this... ' The creation of the control and the call of the method works without error Set searchControl = Server.CreateObject("WebSiteSearch.SiteSearch.1") theResults = searchControl.SearchHTM ( "C:\SomeFolderToSearch", searchPhrase )