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. Some ATL Problems ?? Ask for help

Some ATL Problems ?? Ask for help

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionc++com
6 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 In Atl project ,how can I return the user define type? For example , I have define a Struct ,and I want to return the Struct type in a function, and I plan to utilize the return Struct type in VB through the com. What should I do ? I have try some ways ,but failed. Another similar problem. I have two ATL Object in my Atl project , Teacher and Student . And student is a private property of Teacher ,now I want to construct a function in Teacher to return the Student property .How should I do ? Sincerely ask for help. Who can tell me how to do , or give me some similar source code which resovle the above problems . I'll appreciate it . Regards.

    D 1 Reply Last reply
    0
    • L Leesen

      Hi, all In Atl project ,how can I return the user define type? For example , I have define a Struct ,and I want to return the Struct type in a function, and I plan to utilize the return Struct type in VB through the com. What should I do ? I have try some ways ,but failed. Another similar problem. I have two ATL Object in my Atl project , Teacher and Student . And student is a private property of Teacher ,now I want to construct a function in Teacher to return the Student property .How should I do ? Sincerely ask for help. Who can tell me how to do , or give me some similar source code which resovle the above problems . I'll appreciate it . Regards.

      D Offline
      D Offline
      Dudi Avramov
      wrote on last edited by
      #2

      In the IDL file do the following: typedef struct { int x; int y; } POINT; interface IMyInterface : IUnknown { [propget, helpstring("property Point")] HRESULT Point([out, retval] POINT *pVal); Note that the iterface inherits from IUnknown (Custom interface) and not from IDispatch (Dual interface). Goodluck, Dudi

      L 2 Replies Last reply
      0
      • D Dudi Avramov

        In the IDL file do the following: typedef struct { int x; int y; } POINT; interface IMyInterface : IUnknown { [propget, helpstring("property Point")] HRESULT Point([out, retval] POINT *pVal); Note that the iterface inherits from IUnknown (Custom interface) and not from IDispatch (Dual interface). Goodluck, Dudi

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

        And how can I construct the CStudent object in CTeacher. Details as follows. In the construction function of the CTeacher : CTeacher() { IStudent * m_student =new CStudent(); return; } There are some compiler errors. It says that the CStudent cannot instantiate abstract class due to following members:QueryInterface,AddRef,Release. How should I do to resolve the problem. thx. Regards.

        D 1 Reply Last reply
        0
        • L Leesen

          And how can I construct the CStudent object in CTeacher. Details as follows. In the construction function of the CTeacher : CTeacher() { IStudent * m_student =new CStudent(); return; } There are some compiler errors. It says that the CStudent cannot instantiate abstract class due to following members:QueryInterface,AddRef,Release. How should I do to resolve the problem. thx. Regards.

          D Offline
          D Offline
          Dudi Avramov
          wrote on last edited by
          #4

          You cannot create a com object by using new. Use CComObject instead: CComObject<CStudent> *m_student; HRESULT hr = CComObject<CStudent>::CreateInstance(&m_student);

          1 Reply Last reply
          0
          • D Dudi Avramov

            In the IDL file do the following: typedef struct { int x; int y; } POINT; interface IMyInterface : IUnknown { [propget, helpstring("property Point")] HRESULT Point([out, retval] POINT *pVal); Note that the iterface inherits from IUnknown (Custom interface) and not from IDispatch (Dual interface). Goodluck, Dudi

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

            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.

            D 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.

              D Offline
              D Offline
              Dudi Avramov
              wrote on last edited by
              #6

              In VB you should write set s = t.OneStudent. Now, you don't support 'get' function but 'put' function. This is why VB send you that error. Add the following: STDMETHODIMP CTeacher::get_OneStudent(IStudent **pVal) { // put your code return S_OK; } you should change the IDL file, as well. Goodluck, Dudi

              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