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. trouble in ATL

trouble in ATL

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
5 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.
  • N Offline
    N Offline
    novachen
    wrote on last edited by
    #1

    Hi! There are two classes in my ATL dll. One called Apple, another called Banana. Banana has a method to create and return an Apple. In IDL it will be like GetApple([out, retval] IApple** ret) But i don't know how to write this method in the cpp of bananna. I wrote: { CApple* p = new CApple(); *ret = p; } But the comiler said CApple is an abstract class and can't be created. Do you have any experience in this thing?

    M 1 Reply Last reply
    0
    • N novachen

      Hi! There are two classes in my ATL dll. One called Apple, another called Banana. Banana has a method to create and return an Apple. In IDL it will be like GetApple([out, retval] IApple** ret) But i don't know how to write this method in the cpp of bananna. I wrote: { CApple* p = new CApple(); *ret = p; } But the comiler said CApple is an abstract class and can't be created. Do you have any experience in this thing?

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      What's the definition of the Apple class? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

      N 1 Reply Last reply
      0
      • M Michael Dunn

        What's the definition of the Apple class? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

        N Offline
        N Offline
        novachen
        wrote on last edited by
        #3

        In fact, in my test project, Apple can be a class without any method or property. I just don't know how to create a simple object with COM interface in another object's method inside COM DLL. the idl of apple is interface IApple : IDispatch{ }; and idl of banana is interface IBanana : IDispatch{ [id(1), helpstring("GetApple")] HRESULT GetApple([out,retval] IApple** apple); }; And i try to implement the GetApple as #include "stdafx.h" #include "Banana.h" #include "Apple.h" // CBanana STDMETHODIMP CBanana::GetApple(IApple** apple) { *apple = new CApple(); return S_OK; } VC7 said the CApple is abstract class, so can't be created. Any idea?

        M 1 Reply Last reply
        0
        • N novachen

          In fact, in my test project, Apple can be a class without any method or property. I just don't know how to create a simple object with COM interface in another object's method inside COM DLL. the idl of apple is interface IApple : IDispatch{ }; and idl of banana is interface IBanana : IDispatch{ [id(1), helpstring("GetApple")] HRESULT GetApple([out,retval] IApple** apple); }; And i try to implement the GetApple as #include "stdafx.h" #include "Banana.h" #include "Apple.h" // CBanana STDMETHODIMP CBanana::GetApple(IApple** apple) { *apple = new CApple(); return S_OK; } VC7 said the CApple is abstract class, so can't be created. Any idea?

          M Offline
          M Offline
          Michael Dunn
          wrote on last edited by
          #4

          Ah, I see now. See Q181265[^] Basically, your CApple doesn't implement any of the IUnknown methods, that's why you can't create instances of it. You instead create instances of CComObject, which does implement IUnknown. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

          N 1 Reply Last reply
          0
          • M Michael Dunn

            Ah, I see now. See Q181265[^] Basically, your CApple doesn't implement any of the IUnknown methods, that's why you can't create instances of it. You instead create instances of CComObject, which does implement IUnknown. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER

            N Offline
            N Offline
            novachen
            wrote on last edited by
            #5

            Thanks! I wanna ask for a little more. In Apple i try to hide a struct. It is not on the interface to the client. But the other class in the COM know it is there, and can access it. in apple.h struct Image { int num; }; // CApple class ATL_NO_VTABLE CApple : public CComObjectRootEx, public CComCoClass, public IDispatchImpl { public: Image img; CApple() { } The banana add a method interface IBanana : IDispatch{ [id(1), helpstring("GetApple")] HRESULT GetApple([out,retval] IApple** apple); [id(2), helpstring("QueryApple")] HRESULT QueryApple([in] IApple* apple, [out,retval] int * ret); }; And in banana.cpp i try STDMETHODIMP CBanana::GetApple(IApple** apple) { CApple* p = new CComObject(); p->img.num = 100; *apple = p; return S_OK; } STDMETHODIMP CBanana::QueryApple(IApple* apple, int* ret) { CApple* p = dynamic_cast(apple); *ret = p->img.num; return S_OK; } But when i use this dll in c#, it always get a System.ExecutionEngineException. the script is FruitLib.Banana banana = new FruitLib.BananaClass(); FruitLib.Apple apple = banana.GetApple(); int n = banana.QueryApple(apple); Any idea then? Thanks!

            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