Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JNI GetMethodID Problem

843829Jan 24 2006
Hi, i have a big problem. I am in a project that composed from ATL, JNI technologies and a Java application.
I have been using a timer with C++ that calls a jni function. Then this jni function calls another java function. The problem is that "GetMethodID" in jni function returns null when called from Timer Procedure. (Timer procedure is a static function.) If it is called from any other function(not timer procedure), it works fine.( I used attachCurrentThread, but it didn't change.)

i am using JNI 1.2. Thanks in advance.

//SetTimer call:
SetTimer((HWND)0, 1, 3000, (TIMERPROC) TimerProc);
//Timer Procedure Function decleration:
static VOID CALLBACK TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime );
//Timer Procedure Function:
VOID CALLBACK OutlookPlugin::TimerProc( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime ) {
	OutlookPlugin *pPluginClass = (OutlookPlugin *)pObject; // cast the void pointer
	pPluginClass->getMailTextFromMessman();
}
//Called from timer procedure function
void __stdcall OutlookPlugin::getMailTextFromMessman(){
	unsigned short *message = ::getMessageAsText();//getMessageAsText is declared in jni project...
	if(message!=NULL){
		CComQIPtr<Outlook::_Application>outApp(OutlookApplication);
		BSTR name;
		OutlookPlugin::createMailItemFromMTF(message, name, 0);
	}
}
JNI Function:
unsigned short *_stdcall getMessageAsText(){
        jint res = jvm->AttachCurrentThread((void**)&env, NULL);
	jmethodID id = env->GetMethodID(testClass, "checkSendingTextMessage", "()Ljava/lang/String;");
	  
	if(id==NULL)   //id becomes null when called from time procedure
		return NULL;
	
        jstring strJava = (jstring) env->CallObjectMethod( testObject, id );
	env->ExceptionDescribe();
	
	if (strJava != NULL){
		jboolean isCopy = 0;
		const unsigned short *data = env->GetStringChars(strJava, &isCopy);
		
		if (!isCopy){
			env->ReleaseStringChars(strJava,data);
		}
		return (unsigned short *)data;
	}

	return NULL;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 21 2006
Added on Jan 24 2006
0 comments
302 views