Click here to Skip to main content
16,010,392 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Why do I get an asserion error? Pin
1-Oct-01 4:17
suss1-Oct-01 4:17 
GeneralRe: Why do I get an asserion error? Pin
Chris Meech1-Oct-01 4:42
Chris Meech1-Oct-01 4:42 
GeneralBasic Statistics Pin
Paul Selormey1-Oct-01 3:48
Paul Selormey1-Oct-01 3:48 
GeneralRe: Basic Statistics Pin
Mukkie1-Oct-01 5:50
Mukkie1-Oct-01 5:50 
GeneralRe: Basic Statistics Pin
Paul Selormey2-Oct-01 14:02
Paul Selormey2-Oct-01 14:02 
QuestionUse Dll that created in VC++ in Delphi ? Pin
1-Oct-01 3:14
suss1-Oct-01 3:14 
AnswerRe: Use Dll that created in VC++ in Delphi ? Pin
Michael P Butler1-Oct-01 3:22
Michael P Butler1-Oct-01 3:22 
GeneralConnection Point Hell, now with added MFC... Pin
Christian Graus1-Oct-01 3:03
protectorChristian Graus1-Oct-01 3:03 
I'm still working through the whole connection point fiasco, with mixed results. OK, I admit it, they aren't mixed, it all blows. I've done a *lot* of reading and at this point I am pretty confident that my connection point is set up properly on the ATL side. I added the IDL manually, like this:

	interface ISAFileDB : IDispatch
	{
		[id(1), helpstring("method Connect")] HRESULT Connect([in] BSTR DatabasePath);
		[id(2), helpstring("method CloseDB")] HRESULT CloseDB();
		[id(3), helpstring("method ScanDir")] HRESULT ScanDir([in] BSTR dir, [in] BSTR substr, [in] BSTR suffix, [out] IEnumSAFileEntry ** Entered, [out] IEnumSAFileEntry ** Changed, [out] IEnumSAFileEntry ** Skipped);
		[id(4), helpstring("method GetDatabase")] HRESULT GetDatabase([out] IEnumSAFileEntry ** Database);
		[id(5), helpstring("method SearchDatabase")] HRESULT SearchDatabase([in] BSTR substr, [in] BSTR suffix, [out] IEnumSAFileEntry **Database);
		[id(6), helpstring("method DeleteRecords")] HRESULT DeleteRecords([in] BSTR substr, [in] BSTR suffix, [in] BOOL bDelete, [out] IEnumSAFileEntry **Deleted);
		[id(7), helpstring("method VerifyDB")] HRESULT VerifyDB([in] BOOL bDelete, [out] IEnumSAFileEntry **Deleted);
		[id(8), helpstring("method DoTest")] HRESULT DoTest();
	};

[
	uuid(224F8579-E559-436C-9FDD-D0CC70E6E013),
	version(1.0),
	helpstring("SADatabase 1.0 Type Library")
]
	interface ISAFileDBEvents : IDispatch
	{
		[helpstring("method OnTest")] HRESULT OnTest();
	};

[
	uuid(95B90562-7A7E-4f61-8FE1-D0BB9548294A),
	version (1.0),
	helpstring("SAFileDBEvents 1.0 Type Library")
]

library SADATABASELib
{
	importlib("stdole32.tlb");
	importlib("stdole2.tlb");

	[
		uuid(2CADF3A1-A5C9-4D89-A8ED-BEA59BDE6857),
		helpstring("SAFileDB Class")
	]
	coclass SAFileDB
	{
		[default] interface ISAFileDB;
		[default, source] interface ISAFileDBEvents;
	};
	[
		uuid(100F3513-A370-434C-AD21-274AF9F3614E),
		helpstring("SAFileEntry Class")
	]


Then I added a method called DoTest to the ISAFileDB interface, and set up the connection point. I added code for a messagebox to DoTest, and left Fire_DoTest untouched.

Now on the MFC side I set up a class derived from CCmdTarget, like this:

class CConnPt : public CCmdTarget
{
	DECLARE_DYNCREATE(CConnPt)

	CConnPt();           // protected constructor used by dynamic creation

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CConnPt)
	public:
	virtual void OnFinalRelease();
	//}}AFX_VIRTUAL

// Implementation
protected:
	virtual ~CConnPt();

	// Generated message map functions
	//{{AFX_MSG(CConnPt)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
	// Generated OLE dispatch map functions
	//{{AFX_DISPATCH(CConnPt)
		afx_msg void DoTest();
	//}}AFX_DISPATCH
	DECLARE_DISPATCH_MAP()
	DECLARE_INTERFACE_MAP()
};


and in the .cpp file:

#import "..\ATL\SADatabase\SADatabase.tlb" no_namespace, named_guids

/////////////////////////////////////////////////////////////////////////////
// CConnPt

IMPLEMENT_DYNCREATE(CConnPt, CCmdTarget)

CConnPt::CConnPt()
{
	EnableAutomation();
}

CConnPt::~CConnPt()
{
}


void CConnPt::OnFinalRelease()
{
	// When the last reference for an automation object is released
	// OnFinalRelease is called.  The base class will automatically
	// deletes the object.  Add additional cleanup required for your
	// object before calling the base class.

	CCmdTarget::OnFinalRelease();
}


BEGIN_MESSAGE_MAP(CConnPt, CCmdTarget)
	//{{AFX_MSG_MAP(CConnPt)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BEGIN_DISPATCH_MAP(CConnPt, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CConnPt)
		DISP_FUNCTION(CConnPt, "Test", DoTest, VT_EMPTY, VTS_NONE)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
/*
BEGIN_DISPATCH_MAP(CEventNotifySink, CCmdTarget)
	//{{AFX_DISPATCH_MAP(CEventNotifySink)
	DISP_FUNCTION(CEventNotifySink, "GotEventOne", GotEventOne, VT_EMPTY, VTS_BSTR)
	DISP_FUNCTION(CEventNotifySink, "GotEventTwo", GotEventTwo, VT_EMPTY, VTS_BSTR)
	//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
*/
// Note: we add support for IID_IConnPt to support typesafe binding
//  from VBA.  This IID must match the GUID that is attached to the 
//  dispinterface in the .ODL file.

// {C3996B23-CBCE-443F-B5D8-A98A9D1B62F1}
static const IID IID_IConnPt =
{ 0xc3996b23, 0xcbce, 0x443f, { 0xb5, 0xd8, 0xa9, 0x8a, 0x9d, 0x1b, 0x62, 0xf1 } };

BEGIN_INTERFACE_MAP(CConnPt, CCmdTarget)
	INTERFACE_PART(CConnPt, IID_ISAFileDB, Dispatch)
END_INTERFACE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CConnPt message handlers

void CConnPt::DoTest() 
{
	AfxMessageBox("sdfsdf");
}


Now I do *this* when a button is pushed in the app

CoInitialize(NULL);
m_pConnPt = new CConnPt();

LPUNKNOWN pUnkSink = m_pConnPt->GetIDispatch(FALSE);

ISAFileDBPtr pIFind(__uuidof(SAFileDB));

IUnknown * pUnk = NULL;

pIFind->QueryInterface(IID_IUnknown, (void**)&pUnk);

AfxConnectionAdvise(pUnk, IID_ISAFileDBEvents, pUnkSink, FALSE, &m_dwCookie);

pIFind->DoTest();

AfxConnectionUnadvise(pUnk, IID_ISAFileDBEvents, pUnkSink, FALSE, m_dwCookie);

pUnk->Release();
CoUninitialize();


DoTest causes the dialog from the server to come up, but not the one in my CCmdTarget class, instead it crashes in comip.h, in the line:

void _Release() throw()
{
    if (m_pInterface != NULL) {
        m_pInterface->Release();
    }
}


in the Release() call. The disturbing thing is if I trace it back it is the END of my function, when everything is going out of scope, indicating to me that I've got real problems, because by the time it crashes, the time for my connection point to work has well and truly passed.

Can *anyone* see what I am doing wrong and/or provide any advice ? The rest of this project came together like a dream, but the connection points have been an ongoing nightmare...Cry | :((

Christian

As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.

Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
GeneralRe: Connection Point Hell, now with added MFC... Pin
NormDroid1-Oct-01 3:18
professionalNormDroid1-Oct-01 3:18 
GeneralRe: Connection Point Hell, now with added MFC... Pin
Christian Graus1-Oct-01 3:26
protectorChristian Graus1-Oct-01 3:26 
GeneralRe: Connection Point Hell, now with added MFC... Pin
Michael P Butler1-Oct-01 3:33
Michael P Butler1-Oct-01 3:33 
GeneralRe: Connection Point Hell, now with added MFC... Pin
Christian Graus1-Oct-01 4:00
protectorChristian Graus1-Oct-01 4:00 
GeneralRe: Connection Point Hell, now with added MFC... Pin
Michael P Butler1-Oct-01 4:16
Michael P Butler1-Oct-01 4:16 
GeneralRe: Connection Point Hell, now with added MFC... Pin
Christian Graus1-Oct-01 10:42
protectorChristian Graus1-Oct-01 10:42 
GeneralRe: Connection Point Hell, now with added MFC... Pin
Michael P Butler1-Oct-01 22:20
Michael P Butler1-Oct-01 22:20 
GeneralFindExecutable Pin
1-Oct-01 2:04
suss1-Oct-01 2:04 
GeneralRe: FindExecutable Pin
Oscar Vazquez1-Oct-01 4:50
Oscar Vazquez1-Oct-01 4:50 
GeneralRe: FindExecutable Pin
Carlos Antollini1-Oct-01 5:16
Carlos Antollini1-Oct-01 5:16 
GeneralRe: FindExecutable Pin
Josh Knox1-Oct-01 7:03
Josh Knox1-Oct-01 7:03 
GeneralRe: FindExecutable Pin
Paolo Messina1-Oct-01 12:43
professionalPaolo Messina1-Oct-01 12:43 
GeneralHELP NEEDED FOR GRAPHICS LIBRARY!!! Pin
Janlim1-Oct-01 0:10
Janlim1-Oct-01 0:10 
GeneralRe: HELP NEEDED FOR GRAPHICS LIBRARY!!! Pin
Christian Graus1-Oct-01 0:21
protectorChristian Graus1-Oct-01 0:21 
GeneralRe: HELP NEEDED FOR GRAPHICS LIBRARY!!! Pin
Janlim1-Oct-01 0:25
Janlim1-Oct-01 0:25 
Generalre:HELP NEEDED FOR GRAPHICS LIBRARY!!! Pin
Janlim1-Oct-01 0:31
Janlim1-Oct-01 0:31 
Generalre:HELP NEEDED FOR GRAPHICS LIBRARY!!! Pin
Janlim1-Oct-01 0:32
Janlim1-Oct-01 0:32 

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.