F
fshawish
Hello all,
I have a C# Class Lib that exposes a public events, methods and
properties. I am referencing this ClassLib from an MFC DIalog app that
is compiled with /CLR. I use gcroot<T> to create and connect and call
the method in the C# Class Lib w/o problems. However, I am having a
hard time sinking the C# events in my managed C++ app. I am using .NET
1.1.
Note that I can do this through COM Interop; however, I am would prefer
to do it natively in the managed environment.
The following code compiles and all works except I never receive the
event.
// CoCreate the CoClass...
m_pConfigAgent = new MyComponents::ConfigDataServerAgent();
// QI for the interface; make sure it's not NULL!
m_pIDvcoConfig = (MyComponents::IDVCOConfigData*) m_pConfigAgent;
if (m_pIDvcoConfig != NULL)
{
CMfcClientSink* sink = new CMfcClientSink;
m_pConfigAgent->DataChanged += new
MyComponents::ConfigDataEventHandler(sink,
&CMfcClientSink::OnDataChanged);
// Intialize the server
m_pIDvcoConfig->Initialize();
m_bDvcoSim = m_pIDvcoConfig->Simulation;
:
}
where, CMfcClientSink is declared as follows:
// __gc sink class object that will act as the event sink
__gc class CMfcClientSink
{
public:
void OnDataChanged();
};
and the interface pointers are delcared as follows:
gcroot<My:Components::ConfigDataServerAgent*> m_pConfigAgent;
gcroot<MyComponents::IDVCOConfigData*> m_pIDvcoConfig;
and lastely, the event handler/method:
void CMfcClientSink::OnDataChanged()
{
AfxMessageBox("DataChanged");
}
Any help would be appreciated...
Fadi
I have a C# Class Lib that exposes a public events, methods and
properties. I am referencing this ClassLib from an MFC DIalog app that
is compiled with /CLR. I use gcroot<T> to create and connect and call
the method in the C# Class Lib w/o problems. However, I am having a
hard time sinking the C# events in my managed C++ app. I am using .NET
1.1.
Note that I can do this through COM Interop; however, I am would prefer
to do it natively in the managed environment.
The following code compiles and all works except I never receive the
event.
// CoCreate the CoClass...
m_pConfigAgent = new MyComponents::ConfigDataServerAgent();
// QI for the interface; make sure it's not NULL!
m_pIDvcoConfig = (MyComponents::IDVCOConfigData*) m_pConfigAgent;
if (m_pIDvcoConfig != NULL)
{
CMfcClientSink* sink = new CMfcClientSink;
m_pConfigAgent->DataChanged += new
MyComponents::ConfigDataEventHandler(sink,
&CMfcClientSink::OnDataChanged);
// Intialize the server
m_pIDvcoConfig->Initialize();
m_bDvcoSim = m_pIDvcoConfig->Simulation;
:
}
where, CMfcClientSink is declared as follows:
// __gc sink class object that will act as the event sink
__gc class CMfcClientSink
{
public:
void OnDataChanged();
};
and the interface pointers are delcared as follows:
gcroot<My:Components::ConfigDataServerAgent*> m_pConfigAgent;
gcroot<MyComponents::IDVCOConfigData*> m_pIDvcoConfig;
and lastely, the event handler/method:
void CMfcClientSink::OnDataChanged()
{
AfxMessageBox("DataChanged");
}
Any help would be appreciated...
Fadi