Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JNI_CreateJavaVM doesn't work for GUI

Reply
Thread Tools

JNI_CreateJavaVM doesn't work for GUI

 
 
James Cassidy
Guest
Posts: n/a
 
      06-19-2004

Can anyone please lend some assistance? I've scanned the newsgroup archives as well as the net,
but not been able to get this to work.

My code to load a jvm works from a console program, but returns -1 when used in an MFC GUI program.
The vfprintf even works in the console version, but not in the MFC version!??




static jint JNICALL my_vfprintf(FILE *fp, const char *format, va_list args)
{
char buf[1024];
_vsnprintf(buf, sizeof(buf), format, args);
return 1;
}


void CTestApp::loadJvm( void )
{
JavaVMInitArgs vm_args;
JavaVMOption options[5];
JavaVM *jvm;
JNIEnv *env;
jint res;

options[0].optionString = "-Djava.compiler=NONE";
options[1].optionString = "-Djava.class.path=c:\\j2sdk1.4.2_04\\jre\\lib\\rt.j ar.";
options[2].optionString = "-Djava.library.path=c:\\j2sdk1.4.2_04\\bin";
options[3].optionString = "-verbose:jni";
options[4].optionString = "vfprintf";
options[4].extraInfo = my_vfprintf;

vm_args.version = JNI_VERSION_1_4;
vm_args.options = options;
vm_args.nOptions = 5;
vm_args.ignoreUnrecognized = JNI_TRUE;

res = JNI_CreateJavaVM( &jvm, (void **) &env, &vm_args );

if( res < 0 ) {
MessageBox( NULL, "JNI_CreateJavaVM failed.", "Error loading Java VM", MB_OK );
}

}

 
Reply With Quote
 
 
 
 
Jim Sculley
Guest
Posts: n/a
 
      06-19-2004
James Cassidy wrote:
> Can anyone please lend some assistance? I've scanned the newsgroup archives as well as the net,
> but not been able to get this to work.
>
> My code to load a jvm works from a console program, but returns -1 when used in an MFC GUI program.
> The vfprintf even works in the console version, but not in the MFC version!??


The jvm shared library (jvm.dll) expects to be in a particular location
relative to the runtime libraries. Did you make any changes from your
console program to your MFC program that might have impacted this?

Jim S.




--
Remove my extraneous mandibular appendages to reply via email.
 
Reply With Quote
 
 
 
 
James Cassidy
Guest
Posts: n/a
 
      06-19-2004
On Sat, 19 Jun 2004 09:58:59 -0400, Jim Sculley <(E-Mail Removed)> wrote:

>James Cassidy wrote:
>> Can anyone please lend some assistance? I've scanned the newsgroup archives as well as the net,
>> but not been able to get this to work.
>>
>> My code to load a jvm works from a console program, but returns -1 when used in an MFC GUI program.
>> The vfprintf even works in the console version, but not in the MFC version!??

>
>The jvm shared library (jvm.dll) expects to be in a particular location
>relative to the runtime libraries. Did you make any changes from your
>console program to your MFC program that might have impacted this?
>
>Jim S.


Thanks for the reply Jim.

No changes. I've installed J2SDK1.4.2_04 in the location c:\j2sdk1.4.2_04. The jvm.dll is in the
location:

c:\j2sdk1.4.2_04\jre\bin\server\jvm.dll

I've rechecked the code many times (there still might be a mistake), but it appears to be the same
as in the examples. I'm wondering, as you suggest, that some dll, lib or jar isn't being found by
the mfc version that is being found by the console version. But I have no idea which.

My project settings link tab has the 'c:\j2sdk1.4.2_04\lib\jvm.lib' library specified.

My dos path is set to:

.....;c:\j2sdk1.4.2_04\jre\bin\server;c:\j2sdk1.4. 2_04\lib;c:\j2sdk1.4.2_04\bin

I have no dos CLASSPATH set.

Does any of this info show where I'm shooting myself in the foot (repeatedly)?

Regards,
Jim.
 
Reply With Quote
 
Manfred Rosenboom
Guest
Posts: n/a
 
      06-21-2004
Hava a look into the src.zip file of your JDK installation.
In this ZIP file you will find the directory launcher, containing some
native files. This files will show you how to create a JVM within a
native C/C++ program.

Best,
Manfred
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      06-21-2004
James Cassidy wrote:

> Does any of this info show where I'm shooting myself in the foot
> (repeatedly)?


You might be able to get some insight by using tools like Dependency Walker
<http://www.dependencywalker.com/>
or FileMon
<http://www.sysinternals.com/ntw2k/source/filemon.shtml>

-- chris


 
Reply With Quote
 
James Cassidy
Guest
Posts: n/a
 
      06-21-2004

Thanks Chris! That did the trick. It gave enough clues for me to figure out that there was a
jvm.dll sitting in my executable directory. It must have been using this one rather than the one
in the JDK installation directory. This was messing everything up as Jim suggested in his reply.

What's interesting is that this type of mistake doesn't produce any clues as to what's happening.

Once again, thanks to everyone for their help!

Regards,
Jim.

On Mon, 21 Jun 2004 09:54:53 +0100, "Chris Uppal" <(E-Mail Removed)-THIS.org> wrote:

>James Cassidy wrote:
>
>> Does any of this info show where I'm shooting myself in the foot
>> (repeatedly)?

>
>You might be able to get some insight by using tools like Dependency Walker
> <http://www.dependencywalker.com/>
>or FileMon
> <http://www.sysinternals.com/ntw2k/source/filemon.shtml>
>
> -- chris
>


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      06-21-2004
On Mon, 21 Jun 2004 09:17:25 -0400, James Cassidy <(E-Mail Removed)> wrote
or quoted :

>Thanks Chris! That did the trick. It gave enough clues for me to figure out that there was a
>jvm.dll sitting in my executable directory. It must have been using this one rather than the one
>in the JDK installation directory. This was messing everything up as Jim suggested in his reply.


Somebody please implement this student project to help deliver us from
such evil.

see http://mindprod.com/projects/pathtool.html

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
JNI_CreateJavaVM() prevents loading the DLL Chao Dong Java 2 04-16-2008 10:05 AM
JNI_CreateJavaVM failing in PAM environment... ggg_2006@post.com Java 0 06-03-2005 12:03 AM
JNI JNI_CreateJavaVM hangs Linux kevin Java 3 05-15-2004 05:33 PM
JNI_CreateJavaVM fails (returns -1) buzz Java 0 05-10-2004 10:54 PM
Call JNI_CreateJavaVM from C++ returns (-1) Steve Java 2 12-22-2003 01:09 PM



Advertisments