You might look at your C++ event sink class. I suspect your error is
probably in there. Maybe you could show your event sink implementation from
your C++ code here. The C# code looks fine to me.
Hi Jayme,
I think this is what you are referring to :) :
// ClientControlEventSink.h
#pragma once
#import "ClientControl.tlb" named_guids raw_interfaces_only
#define IDC_ClientControl 998
// CClientControlEventSink command target
class CClientControlEventSink : public CCmdTarget
{
DECLARE_DYNAMIC(CClientControlEventSink)
public:
CClientControlEventSink();
virtual ~CClientControlEventSink();
virtual void OnFinalRelease();
// ClientControl overrides
void OnStatusChanged();
protected:
DECLARE_MESSAGE_MAP()
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
// ClientControlEventSink.cpp : implementation file
//
#include "stdafx.h"
#include "tryclientcontrol.h"
#include "ClientControlEventSink.h"
// CClientControlEventSink
IMPLEMENT_DYNAMIC(CClientControlEventSink, CCmdTarget)
CClientControlEventSink::CClientControlEventSink()
{
EnableAutomation();
}
CClientControlEventSink::~CClientControlEventSink()
{
}
void CClientControlEventSink::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(CClientControlEventSink, CCmdTarget)
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CClientControlEventSink, CCmdTarget)
DISP_FUNCTION_ID(CClientControlEventSink,"StatusChanged", 0x00000001,
OnStatusChanged,VT_EMPTY,VTS_I4 VTS_I4)
END_DISPATCH_MAP()
// Note: we add support for IID_IClientControlEventSink to support
typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .IDL file.
// {6998F069-5D1D-45A3-9E42-384B6C5FA9B1}
//static const IID IID_IClientControlEventSink =
//{ 0x6998F069, 0x5D1D, 0x45A3, { 0x9E, 0x42, 0x38, 0x4B, 0x6C, 0x5F,
0xA9, 0xB1 } };
static const IID IID_IClientControlEventSink =
{ 0x548B0682, 0xAA8E, 0x437C, { 0x83, 0x9C, 0x87, 0x7B, 0xF9, 0xCA,
0xDE, 0x3B } };
BEGIN_INTERFACE_MAP(CClientControlEventSink, CCmdTarget)
INTERFACE_PART(CClientControlEventSink,
ClientControl::DIID_IClientControl_Events, Dispatch)
END_INTERFACE_MAP()
// CClientControlEventSink message handlers
void CClientControlEventSink::OnStatusChanged()
{
int i = 1000;
}
// ATlClientContainer.h : Declaration of the CATlClientContainer
#pragma once
#include "resource.h" // main symbols
#include <atlhost.h>
#include <string>
#import "ClientControl.tlb" named_guids raw_interfaces_only
#define IDC_ClientControl 998
// CATlClientContainer
class CATlClientContainer;
typedef IDispEventImpl<IDC_ClientControl, CATlClientContainer,
&ClientControl::DIID_IClientControl_Events,
&ClientControl::LIBID_ClientControl> VoipIMControlEvent;
class CATlClientContainer :
public CAxDialogImpl<CATlClientContainer>,
public VoipIMControlEvent
{
public:
CATlClientContainer()
{
}
~CATlClientContainer()
{
}
enum { IDD = IDD_ATLCLIENTCONTAINER };
BEGIN_MSG_MAP(CATlClientContainer)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
CHAIN_MSG_MAP(CAxDialogImpl<CATlClientContainer>)
END_MSG_MAP()
BEGIN_SINK_MAP(CATlClientContainer)
//Make sure the Event Handlers have __stdcall calling convention
SINK_ENTRY_EX(IDC_ClientControl,
ClientControl::DIID_IClientControl_Events, 0x00000001, StatusChanged)
SINK_ENTRY_EX(IDC_ClientControl,
ClientControl::DIID_IClientControl_Events, 0x00000002, Notification)
END_SINK_MAP()
// Handler prototypes:
// LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandled);
// LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl,
BOOL& bHandled);
// LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled);
LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
protected:
// Events
VOID __stdcall StatusChanged()
{
}
VOID __stdcall Notification()
{
//OnClientControlNotification();
}
private:
CComPtr<ClientControl::IClientControl> m_pClientControl;
CAxWindow m_VoipWnd;
};