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. ATL / WTL / STL
  4. ATL Component with C++ class

ATL Component with C++ class

Scheduled Pinned Locked Moved ATL / WTL / STL
c++tutorialquestion
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.
  • Y Offline
    Y Offline
    yang__lee
    wrote on last edited by
    #1

    Hi, I want to build a ATL wrapper on c++ class and would like to use that component in VB. I insert an ATL class MyAWrapper I add one property HRESULT String([out, retval] BSTR *pVal) one method HRESULT ClearString() to IMyAWrapper. IDL file shows it then in MyAWrapper.h i put following c++ code class foo { std::string m_str; public: foo(std::string bar, bool baz) : m_str(bar) { if (baz) throw std::exception(); } std::string get_string(void) { return m_str; } void clear_string(void) { m_str = ""; } }; in ATL class.. class MyAWrapper I addfollowing code. STDMETHOD(FinalConstruct)(void) { try { m_pfoo = new foo("test", false); } catch (...) { return E_FAIL; } return S_OK; } in MyAWrapper.cpp, I put STDMETHODIMP MyAWrapper::get_String(BSTR *pVal) { // TODO: Add your implementation code here if (pVal == NULL) return E_POINTER; std::string sTemp = m_pfoo->get_string(); *pVal = ::SysAllocStringLen(sTemp.c_str(), sTemp.length()); return *pVal ? S_OK : E_OUTOFMEMORY; } STDMETHODIMP MyAWrapper::ClearString() { // TODO: Add your implementation code here m_pfoo->clear_string(); } Please tell me Are these stpes OK?? or where to put c++ code? I can not compile the project.. I get around 34 errors one of which is 'std' : is not a class or namespace name Pleasew tell me how to have this perfectly function. Thanks Lee

    Leya

    P 1 Reply Last reply
    0
    • Y yang__lee

      Hi, I want to build a ATL wrapper on c++ class and would like to use that component in VB. I insert an ATL class MyAWrapper I add one property HRESULT String([out, retval] BSTR *pVal) one method HRESULT ClearString() to IMyAWrapper. IDL file shows it then in MyAWrapper.h i put following c++ code class foo { std::string m_str; public: foo(std::string bar, bool baz) : m_str(bar) { if (baz) throw std::exception(); } std::string get_string(void) { return m_str; } void clear_string(void) { m_str = ""; } }; in ATL class.. class MyAWrapper I addfollowing code. STDMETHOD(FinalConstruct)(void) { try { m_pfoo = new foo("test", false); } catch (...) { return E_FAIL; } return S_OK; } in MyAWrapper.cpp, I put STDMETHODIMP MyAWrapper::get_String(BSTR *pVal) { // TODO: Add your implementation code here if (pVal == NULL) return E_POINTER; std::string sTemp = m_pfoo->get_string(); *pVal = ::SysAllocStringLen(sTemp.c_str(), sTemp.length()); return *pVal ? S_OK : E_OUTOFMEMORY; } STDMETHODIMP MyAWrapper::ClearString() { // TODO: Add your implementation code here m_pfoo->clear_string(); } Please tell me Are these stpes OK?? or where to put c++ code? I can not compile the project.. I get around 34 errors one of which is 'std' : is not a class or namespace name Pleasew tell me how to have this perfectly function. Thanks Lee

      Leya

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      yang__lee wrote:

      std' : is not a class or namespace name

      Probably, you forgot to include header, string in this case.


      Prasad MS MVP -  VC++

      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