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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. COM
  4. ATL Problems??

ATL Problems??

Scheduled Pinned Locked Moved COM
c++comtestingtools
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.
  • L Offline
    L Offline
    Leesen
    wrote on last edited by
    #1

    Hi, all Some problems about ATL Com: 1.I have create two ATL Object: CStudent and CTeacher . The simple source code listed as follow: (some code auto generated by ATL have been skiped) class CStudent { private: long m_age; public: CStudent():m_age(10) { } //...other code auto generated by ATL }; class CTeacher { private: IStudent* m_aStudent; public: CTeacher() { //create an instance of the com CoCreateInstance(CLSID_Student,NULL,CLSCTX_ALL,IID_IStudent, (void**)&m_aStudent); } //...other code auto generated by ATL } 2.Then I add a "IStudent * OneStudent" property for ITeacher ,to access the m_aStudent. The implemention of the property are listed as below: STDMETHODIMP CTeacher::get_OneStudent(IStudent *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here *pVal = * m_aStudent; return S_OK; } STDMETHODIMP CTeacher::put_OneStudent(IStudent *newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here *m_aStudent = *newVal ; return S_OK; } 3.Now I type some VB code to test the com ,but some compiler errors occurrs. VB Code: Dim s As Student Dim t As New Teacher s = t.OneStudent the last sentence "s = t.OneStudent" have compiler errors. Errors:function or interface marked as restricted ,or the function use an Automation type not supported in Visual Basic I guess the errors caused by the type dismatch between IStudnet and CStudent.But I did not know how to resolve it . So who can tell me how to return the m_aStudent that can be supproted in vb?? thx. Regards.

    V 1 Reply Last reply
    0
    • L Leesen

      Hi, all Some problems about ATL Com: 1.I have create two ATL Object: CStudent and CTeacher . The simple source code listed as follow: (some code auto generated by ATL have been skiped) class CStudent { private: long m_age; public: CStudent():m_age(10) { } //...other code auto generated by ATL }; class CTeacher { private: IStudent* m_aStudent; public: CTeacher() { //create an instance of the com CoCreateInstance(CLSID_Student,NULL,CLSCTX_ALL,IID_IStudent, (void**)&m_aStudent); } //...other code auto generated by ATL } 2.Then I add a "IStudent * OneStudent" property for ITeacher ,to access the m_aStudent. The implemention of the property are listed as below: STDMETHODIMP CTeacher::get_OneStudent(IStudent *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here *pVal = * m_aStudent; return S_OK; } STDMETHODIMP CTeacher::put_OneStudent(IStudent *newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here *m_aStudent = *newVal ; return S_OK; } 3.Now I type some VB code to test the com ,but some compiler errors occurrs. VB Code: Dim s As Student Dim t As New Teacher s = t.OneStudent the last sentence "s = t.OneStudent" have compiler errors. Errors:function or interface marked as restricted ,or the function use an Automation type not supported in Visual Basic I guess the errors caused by the type dismatch between IStudnet and CStudent.But I did not know how to resolve it . So who can tell me how to return the m_aStudent that can be supproted in vb?? thx. Regards.

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

      // Must have more than 1 inderection of pointer // In idl-file [...] HRESULT OneStudent([out,retval]IStudent* *pVal); STDMETHODIMP CTeacher::get_OneStudent(IStudent* *pVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here *pVal = m_aStudent; if( m_aStudent != NULL ) m_aStudent->AddRef(); return S_OK; } // In idl-file [...] HRESULT OneStudent([in]IStudent* newVal); STDMETHODIMP CTeacher::put_OneStudent(IStudent *newVal) { AFX_MANAGE_STATE(AfxGetStaticModuleState()) // TODO: Add your implementation code here if( m_aStudent != NULL ) m_aStudent->Release(); m_aStudent = newVal ; if( m_aStudent != NULL ) m_aStudent->AddRef(); return S_OK; } In VB you should use the "Set" operator to assign one object to another. Set s = t.OneStudent 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