Jump to content
Excelsior Forums
rdrsdr

JetPerfect dll and Delphi

Recommended Posts

Greetings.

I succesfully created a jet dll and I'm calling it from a delphi app using JNI based on the sample delievered with jet. Now I'm trying to execute the same delphi app but calling a "jet-perfected" dll but the JNI method env.FindClass does not find anything.

In the Jet article "HOWTO: Create a standalone Java DLL and invoke it from C" is told that the c code must be compiled with the -DDynamicUseDLL compiler argument. I'd like to know the delphi argument do do the same.

Thanks in advance and regards

Share this post


Link to post
Share on other sites

-DDynamicUseDLL command-line switch is only for the sample attached to the article - note the conditional compilation

#ifdef DynamicUseDLL 
...

.

Both samples\Invocation\cMain and samples\Invocation\DelphiMain samples in JET 3.7 already use dynamic loading, so there is no need in additional switches.

Therefore, I recommend you to use samples\Invocation\DelphiMain as a starting point.

Share this post


Link to post
Share on other sites

I tried the example(DelphiMain) provided by JET and i get the same error.

Note: The error only occurs only in the perfect mode only with delphi. In case of the example the dll was compiled using the +perfect flag and .usg files are created and used to create a complete dll. But when running the example using the perfect version of dll , the find class call in the test.pas returns null.  Also the previous versions of JET do not exhibit this error.

Share this post


Link to post
Share on other sites

You should change the value of the variable 'JvmModuleName' from "xkrn<ver>" to "dllClass.dll" (in JNI.pas) and recompile 'test.pas' to get it work.

Share this post


Link to post
Share on other sites

oh i forgot to mention. That is already done. Let me show where exactly i get the error after i did a trace on the example (DelphiMain)

procedure loadDLL (name: PAnsiChar);

var

 dllClassHandle: THandle;

begin

  dllClassHandle := LoadLibrary (name);

     dllClassHandle := 0;

   if dllClassHandle = 0 then

   begin

     Write (#13#10'error LoadLibrary'#13#10);

     Halt (1);

   end;

  dllClass := env^.FindClass(env, name);

   if not Assigned (dllClass) then

   begin

     Write (#13#10'DLL not loaded'#13#10);

     Halt (1);

   end;

  Write ('DLL loaded'#13#10);

end;

The error i am getting is "DLL not loaded" and that error is only thrown at one place when a env^.findclass is called in the above piece of code.

The usg file is also not updated when this error is thrown. so there isnt even an issue with the dll.

env^.findClass seems to return a null. I tried it with different JVM's compiled(1.4.1 and 1.4.2 ) still no luck.

the prj file looks like this.

-gendll+

-perfect+

-outputname = dllClass

-UsgFileAutoCompletion = SAFE

-IncludeTimeZoneInfo+

-IncludeLoggingAPI+

-IncludeDetectedLocales+

!module dllClass.class

!module test.usg

am i missing any flag that could make this work with delphi.

Share this post


Link to post
Share on other sites

I got exactly the same error before changing the JvmModuleName value. Please verify that you changed it correctly and have recompiled test.pas (with command "dcc32 /cc test.pas"). Recompilation of the DLL itself is not required.

The code in JNI.pas should look like

const
 {$IFDEF WIN32}
   {$IFDEF JDK1_1}
   JvmModuleName = 'javai.dll';
   {$ELSE}
     {$IFDEF JETRT}

     // correct this declaration to the respective name of DLL from JET/BIN
     JvmModuleName = 'dllClass.dll'; 

     {$ELSE}
     JvmModuleName = 'jvm.dll';
     {$ENDIF}
   {$ENDIF}
 {$ENDIF}
 {$IFDEF LINUX}
 JvmModuleName = 'libjvm.so';
 {$ENDIF}

If the problem persists, please contact us at java@excelsior-usa.com

Share this post


Link to post
Share on other sites

I finally figured out the problem. It was an incomplete .usg file during the run of delphiMain in perfect mode.

Though i always suspected this.Initially when it ran the example it would throw incomplete usg files while doing a loadlibrary of the dll. But once it got over that it would reach the FindClass call and die there. But would never complain about incomplete usg file.

I am myself unsure how i did it but i somehow coaxed it to output the extra usg that it wasnt throwing out before. And once i got hold of that and rebuilt the dll everythingl started working gracefully in the perfect mode.

Thanks though to MAVR for crucial help extended.

Share this post


Link to post
Share on other sites

×