Posted By:
Laurent_Delrue
Posted On:
Friday, April 27, 2001 02:53 AM
Hi, I have a C++ dll (written with Borland C++ Builder) which contains a Form with on it a Timer object. On the other side, I have a Java class calling functions from that C++ dll. The purpose is : Java calls function A() from C++ Dll, Function A() starts the Timer, At given Timer intervals, the C++ dll does a callback in the Java class. The C++ dll Form is created in the JNI_OnLoad function. The problem: The Timer does not run at all, so no callback is performed. I think that in fact it stops as soon function A() exits. I've remarked this when un error occurred in A(), causing a Message Box to appear and waiting to c
More>>
Hi,
I have a C++ dll (written with Borland C++ Builder) which contains a
Form with on it a Timer object.
On the other side, I have a Java class calling functions from that
C++ dll.
The purpose is :
Java calls function A() from C++ Dll,
Function A() starts the Timer,
At given Timer intervals, the C++ dll does a callback in the Java
class.
The C++ dll Form is created in the JNI_OnLoad function.
The problem: The Timer does not run at all, so no callback is
performed.
I think that in fact it stops as soon function A() exits. I've
remarked this when un error occurred in A(), causing a Message Box to
appear and waiting to click the OK button, the Timer was running.
Some code ::
Header file :
//-------------------------------------------------------------------
#ifndef CallBackH
#define CallBackH
//-------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
//-------------------------------------------------------------------
class TCallBackForm : public TForm
{
__published: // IDE-managed Components
TTimer *Timer1;
void __fastcall Timer1Timer(TObject *Sender);
private: // User declarations
public: // User declarations
JavaVM *cached_jvm;
jobject Loader;
jclass Class_Test;
jmethodID MID_Test_notify;
__fastcall TCallBackForm(TComponent* Owner);
void __fastcall enableTimer();
};
extern "C" JNIEXPORT void JNICALL Java_Test_initCppSide(JNIEnv *env,
jobject obj);
//-------------------------------------------------------------------
extern PACKAGE TCallBackForm *CallBackForm;
//-------------------------------------------------------------------
#endif
Some functions in the cpp file ::
//The A() function I was talking about :
JNIEXPORT void JNICALL Java_Test_initCppSide(JNIEnv *env, jobject
obj) {
// Enable Timer
CallBackForm->Timer1->Enabled = true;
printf("Timer enabled
");
}
void __fastcall TCallBackForm::Timer1Timer(TObject *Sender)
{
printf("Timer is running
");
}
//-------------------------------------------------------------------
The line "Timer is running" never appears.
Any ideas what I am doing wrong here ??
Kind regards,
Laurent.
<<Less