Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. COM Component Returning An Array to VBScript

COM Component Returning An Array to VBScript

Scheduled Pinned Locked Moved COM
helpc++comsysadmindata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Doug Knudson
    wrote on last edited by
    #1

    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 )

    V 1 Reply Last reply
    0
    • D Doug Knudson

      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 )

      V Offline
      V Offline
      Vi2
      wrote on last edited by
      #2

      Your problem is the usage of BSTR value after the _bstr_t's destructor. Change bData's type from BSTR to _bstr_t: _bstr_t bData; ... bData = documentTypeArray.GetAt(row); sa.PutElement(elementIndex,(BSTR) bData); With best wishes, Vita

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups