Implement a COM Event Listener and a callback mechanism in a DLL
843829Mar 8 2005 — edited Mar 8 2005Hi!
I'm trying to develop a DLL in C++ callable via JNI through an example Java class.
In this DLL I have to implement an interface of a third party COM library (called ICustomClientGroupDataEvent).
This interface fires events periodically that I want to catch in order to pass them to a Java application.
In my DLL I've just develop a C++ class (a sink class) that implement this interface but I can't catch any events.
I'm going to post some pseudo-code:
/*
JFalconUtility.java: this class exposes a native method for retrieve the events fired by the COM interface
public class JFalconUtility {
public static native void listenToBus(); //this is the native method
static {
System.loadLibrary("JFalcon"); //JFalcon is the name of my DLL
}
*/
/*
TestListener.java: this class calls the static native methode exposed by JFalconUtility
public class TestListener extends Thread {
public TestListener() {}
public void run() {
jfalcon.JFalconUtility.listenToBus(); //native method call
}
public static void main(String[] args) {
TestListener tl = new TestListener();
tl.start();
}
}
*/
/* jfalcon_JFalconUtility.cpp
JNIEXPORT void JNICALL Java_jfalcon_JFalconUtility_listenToBus(JNIEnv *jenv, jclass jcl) {
globalEnv = jenv;
CJFalcon jf; //a reference to the DLL
jf.listenToBus(); //cal to the correct method in the DLL
}
/*CGroupDataEventListener.h: the class that implement the third party COM interface
class CGroupDataEventListener : public ICustomClientGroupDataEvent {
protected:
int m_refCount;
IConnectionPoint* m_pConnectionPoint;
DWORD m_dwConnection;
public:
...
/*********** IUnknown methods****************/
STDMETHODIMP QueryInterface(REFIID riid,void **ppvObj);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
/***********************************************************************/
/*********** ICustomClientGroupDataEvent methods ****************/
.....................
......................
/********************************************************************/
STDMETHODIMP AttachToSource(IGroupDataTransferPtr pGroupData); //method to advise event source to attach to this sink
};
*/
/*CJFalcon.cpp: DLL implementation file
void CJFalcon::listenToBus() {
if(initCOMEnv()) {
if(openBusConnection(ConnectionModeLLBusmon) ) {
if(m_ptrGroupDataTransfer != NULL) {
m_EventListener = new CGroupDataEventListener(); //new instance of the sink class
m_EventListener->AddRef();
m_EventListener->AttachToSource(m_ptrGroupDataTransfer);
...
*/
Sorry for the length of my message!
Thanks so much!