trouble in ATL
-
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?
-
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?
What's the definition of the
Apple
class? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER -
What's the definition of the
Apple
class? --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIERIn 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?
-
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?
Ah, I see now. See Q181265[^] Basically, your
CApple
doesn't implement any of theIUnknown
methods, that's why you can't create instances of it. You instead create instances ofCComObject
, which does implementIUnknown
. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIER -
Ah, I see now. See Q181265[^] Basically, your
CApple
doesn't implement any of theIUnknown
methods, that's why you can't create instances of it. You instead create instances ofCComObject
, which does implementIUnknown
. --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Latest art~!@#2rDFA#@(#*%$Rfa39f3fqwf--= NO CARRIERThanks! 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!