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. Calling a COM component from ASP

Calling a COM component from ASP

Scheduled Pinned Locked Moved COM
questionc++comtoolsperformance
2 Posts 2 Posters 8 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.
  • P Offline
    P Offline
    pba_
    wrote on last edited by
    #1

    Hi, Here is the question : I develop a COM component using ATL . In this component I have a method called "BeepMe", from where I want to return a BSTR message , as an out parameter : BeepMe ([out] BSTR* pbstrMessage) when I call it from an ASP page (written in Jscript): var strRet; Component.BeepMe(strRet); the strRet is empty . but, if I declare the pbstrMessage as retval ( BeeepMe([out,retval] BSTR* pbstrMessage) ) , and write : var strRet = Component.BeepMe(); everithing works fine . The pbstrMessage is propertly initialized in the method ( *pbstrMessage = ::SysAllocString(L"Beep") ), so that isn't the problem. I know that the VB script interpreter handle the deallocation of memory , and I suppose that is also the ASP case . That is the cause of this behavior ? ( the ASP interpreter free the memory of the returned value ? )

    A 1 Reply Last reply
    0
    • P pba_

      Hi, Here is the question : I develop a COM component using ATL . In this component I have a method called "BeepMe", from where I want to return a BSTR message , as an out parameter : BeepMe ([out] BSTR* pbstrMessage) when I call it from an ASP page (written in Jscript): var strRet; Component.BeepMe(strRet); the strRet is empty . but, if I declare the pbstrMessage as retval ( BeeepMe([out,retval] BSTR* pbstrMessage) ) , and write : var strRet = Component.BeepMe(); everithing works fine . The pbstrMessage is propertly initialized in the method ( *pbstrMessage = ::SysAllocString(L"Beep") ), so that isn't the problem. I know that the VB script interpreter handle the deallocation of memory , and I suppose that is also the ASP case . That is the cause of this behavior ? ( the ASP interpreter free the memory of the returned value ? )

      A Offline
      A Offline
      Alex Gorev
      wrote on last edited by
      #2

      Hi, First of all you should use the SysReAllocString instead of SysAllocString. It's not the source of the problem but it's a correct way of doing things. Before assigning a new value to the pointer you must free the data it's pointing to. STDMETHODIMP CTest::get_Path(BSTR *pVal) { if(pVal == NULL) return E_POINTER; if(!SysReAllocString(pVal, m_bstrPath)) return E_OUTOFMEMORY; return S_OK; } Your problem is that in VBScript and JScript cannot pass parameters by reference to automation properties or methods. Use return values of properties and methods to return a value instead of using byref parameters for this purpose. This approach limits you to one return value. Regards, Alex Gorev, Dundas Software.

      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