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. C / C++ / MFC
  4. how to return a string from COM DLL

how to return a string from COM DLL

Scheduled Pinned Locked Moved C / C++ / MFC
comtutorialquestion
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.
  • M Offline
    M Offline
    Mann Khine
    wrote on last edited by
    #1

    I 've one function that 's written with COM DLL. I want to return a string from that function. function declaration is like that STDMETHODIMP CMyClass::Command() from that function how can I return a string. thanks in advance.

    S 1 Reply Last reply
    0
    • M Mann Khine

      I 've one function that 's written with COM DLL. I want to return a string from that function. function declaration is like that STDMETHODIMP CMyClass::Command() from that function how can I return a string. thanks in advance.

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      In the .IDL (or ODL file) change the declaration so it looks something like this:

      HRESULT Command([out, retval] BSTR *pOut);
      

      Now the function should look like this:

      STDMETHODIMP CMyClass::Command(BSTR *pOut)
      {
           if ( pOut == NULL )
           {
               return E_POINTER;
           }
       
           *pOut = SysAllocString(L"Your string here!");
           return S_OK;
      }
      

      If you're not familiar with BSTRs you should read up on them. Steve

      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