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. C / C++ / MFC
  4. ATL Problems ?

ATL Problems ?

Scheduled Pinned Locked Moved C / C++ / MFC
c++comtestingtools
5 Posts 4 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.

    C M P 3 Replies 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.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      As I've already told you, you cannot return an instance of your class. You may be able to return a pointer to another COM object, but you cannot return a vanilla class instance. IDispatch interfaces ( i.e. Automation ) also have more restrictions than normal interfaces, if I remember correctly. If a teacher has lots of students, I think my original suggestion of returning their details as XML remains a good one. Christian We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )

      L 1 Reply Last reply
      0
      • C Christian Graus

        As I've already told you, you cannot return an instance of your class. You may be able to return a pointer to another COM object, but you cannot return a vanilla class instance. IDispatch interfaces ( i.e. Automation ) also have more restrictions than normal interfaces, if I remember correctly. If a teacher has lots of students, I think my original suggestion of returning their details as XML remains a good one. Christian We're just observing the seasonal migration from VB to VC. Most of these birds will be killed by predators or will die of hunger. Only the best will survive - Tomasz Sowinski 29-07-2002 ( on the number of newbie posters in the VC forum )

        L Offline
        L Offline
        Leesen
        wrote on last edited by
        #3

        I am a newer to ATL. I think I just return a pointer to another COM object . 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; }

        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.

          M Offline
          M Offline
          Michael P Butler
          wrote on last edited by
          #4

          Is the IDL for get_OneStudent marked as [out,retval] for the IStudent parameter? Is IStudent an IUnknown or IDispatch interface? Michael :-) Time flies like an arrow. Fruit flies like a banana

          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.

            P Offline
            P Offline
            Philippe Mori
            wrote on last edited by
            #5

            You should returns a new object; something like:

            STDMETHODIMP CTeacher::get_OneStudent(IStudent **pVal)
            {
            AFX_MANAGE_STATE(AfxGetStaticModuleState())

            // TODO: Add your implementation code here
            **pVal = * m_aStudent;
            (*pVal)->AddRef();
            return S_OK;
            }

            Also note that others functions need to be modified. For example setting a new student would have to update the pointer (and properly adjusting reference count). As mentionned in another answer, you cannot pass object around but only interface to objects... Philippe Mori

            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