Click here to Skip to main content
15,902,447 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Computer Hangs as soon as any MFC file is executed... Pin
David Crow11-Aug-03 2:40
David Crow11-Aug-03 2:40 
GeneralSharing rights Pin
Member 42425910-Aug-03 22:46
Member 42425910-Aug-03 22:46 
GeneralRe: Sharing rights Pin
David Crow11-Aug-03 2:43
David Crow11-Aug-03 2:43 
GeneralRe: Sharing rights Pin
Member 42425911-Aug-03 20:27
Member 42425911-Aug-03 20:27 
GeneralRe: Sharing rights Pin
David Crow12-Aug-03 2:33
David Crow12-Aug-03 2:33 
GeneralProject Templates - VC6 Pin
peterchen10-Aug-03 22:40
peterchen10-Aug-03 22:40 
GeneralRe: Project Templates - VC6 Pin
Andrew Walker10-Aug-03 23:39
Andrew Walker10-Aug-03 23:39 
GeneralTrouble in ATL Pin
novachen10-Aug-03 22:40
novachen10-Aug-03 22:40 
Hi!
I try to wrap a c++ lib behind a COM dll to make it easy to use by VB or c#.
But i have some troubles. Look the demo:
There is two classes in COM DLL, one called Apple and another called Banana.

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.

struct Image
{
int num;
};
// CApple

class ATL_NO_VTABLE CApple :
public CComObjectRootEx,
public CComCoClass,
public IDispatchImpl
{
public:
Image img;

CApple()
{
}

The class banana has two methods, GetApple create an Apple object and initialize its value, QueryApple try to query the value in the Apple.

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);

What's wrong in my code? Any idea?
Thanks!

GeneralRe: Trouble in ATL Pin
Mike Dimmick11-Aug-03 2:53
Mike Dimmick11-Aug-03 2:53 
GeneralUrgent help needed! Pin
vcseeker10-Aug-03 22:32
vcseeker10-Aug-03 22:32 
GeneralRe: Urgent help needed! Pin
wb10-Aug-03 23:08
wb10-Aug-03 23:08 
GeneralRe: Urgent help needed! Pin
vcseeker11-Aug-03 2:27
vcseeker11-Aug-03 2:27 
QuestionFlowChart Ctrl ? Pin
ScorpioMidget10-Aug-03 22:17
ScorpioMidget10-Aug-03 22:17 
Questionread file wrong? Pin
Member 43880310-Aug-03 21:19
Member 43880310-Aug-03 21:19 
GeneralAlt Key Pin
s o v a n n10-Aug-03 20:45
s o v a n n10-Aug-03 20:45 
GeneralRe: Alt Key Pin
PJ Arends10-Aug-03 20:58
professionalPJ Arends10-Aug-03 20:58 
Generaldetecting network capacity and type Pin
karanba10-Aug-03 20:43
karanba10-Aug-03 20:43 
GeneralDetecting memory leaks Pin
Imtiaz Murtaza10-Aug-03 20:32
Imtiaz Murtaza10-Aug-03 20:32 
GeneralRe: Detecting memory leaks Pin
Anthony_Yio11-Aug-03 0:51
Anthony_Yio11-Aug-03 0:51 
GeneralBind to picture control Pin
henli10-Aug-03 20:16
henli10-Aug-03 20:16 
Questionhow to catch "Access violation Exception" Pin
zecodela10-Aug-03 20:06
zecodela10-Aug-03 20:06 
AnswerRe: how to catch "Access violation Exception" Pin
Michael Dunn10-Aug-03 20:13
sitebuilderMichael Dunn10-Aug-03 20:13 
AnswerRe: how to catch "Access violation Exception" Pin
ullasd10-Aug-03 22:51
ullasd10-Aug-03 22:51 
GeneralRe: how to catch "Access violation Exception" Pin
Anthony_Yio11-Aug-03 0:52
Anthony_Yio11-Aug-03 0:52 
GeneralRe: how to catch "Access violation Exception" Pin
zecodela11-Aug-03 4:47
zecodela11-Aug-03 4:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.