Load the licensing library to get license information : Java - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Load the licensing library to get license information : Java

Hi,

I use the below code to get my custom licencing information as mentioned in your document,

interface TrialLibrary extends Library {
final TrialLibrary INSTANCE = (TrialLibrary) Native.loadLibrary("C:\\Program Files\\yyyt\\aps\\testtrail", TrialLibrary.class); // loads Trial.dll
int ReadSettingsStr(String keyCode, HWND hwnd);
int DisplayRegistrationStr(String keyCode, HWND hwnd);
String GetPropertyValue(String id);
}

private static final String LIBRARY_KEY = "11111";

public static void main(String[] args) {
int i = TrialLibrary.INSTANCE.ReadSettingsStr(LIBRARY_KEY, null); // works fine
System.out.println(TrialLibrary.INSTANCE.GetPropertyValue("Type"));
}

But this throws

#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x046229de, pid=4152, tid=4064
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Client VM (20.1-b02 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [testtrail.DLL+0x229de]
#
# An error report file with more information is saved as:
# D:\STS\workspace\SmarteServices_Release\hs_err_pid4152.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#


Please help me resolve this issue.
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Hi,

Can some please help me with the above issue, I am trying to access the properties of licence using GetPropertyValue as shown above.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Load the licensing library to get license information :

Hi,

After searching more about this on the web it seems the problem usually appears because you are using a beta version of Java.

The solution is to remove the Beta version and install a new and stable release.

Also, I noticed you set the path for the DLL to be loaded from "C:\Program Files", please note that on x64 machines 32 bit applications
are installed in "C:\Program Files (x86)", so you should check this too, if it is the case for you.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Hi,

Thanks for the reply. I tried changing the java version to a stable version. But still i get the same error.

I was able to validate the licence using
TrialLibrary.INSTANCE.ReadSettingsStr(LIBRARY_KEY, null);

I get the error only when i add the below line,
TrialLibrary.INSTANCE.GetPropertyValue("ID")

Could you please provide any working examples for retrieving the properties from dll file.
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Hi,

What are we trying to do :

provide a licence with "number of users" limitation. and access "the number of users" in the application.

How did we try doing?

We tried adding a custom variable in the licence template. And we tried accessing the variable as shown above, Which resulted in the above issue.

What we need?

Do we have an alternative approach to achieve this? Please help us in achieving the above functionality.
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Hi,

Can some please let me if this is possible atleast. We have been searching for this now for a while.
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Load the licensing library to get license information :

Hi,

The samples we've provided are for integrating the licensing library in a java application that is launched using our java product support. Is your application using this support?

If not, you will have to load the library manually, as we showed in the C++/.NET samples, with additional steps. We will start an investigation for this too and
we'll be back with more details ASAP.

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Thanks for the reply,

We are not using "java product support", Instead we are loading the .dll file manually in the java program. (as shown above).

I would be of great help if you can provide a Java example to retrieve the properties from DLL.


Thanks,
Murugavel
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Load the licensing library to get license information :

Hi Murugavel,

We managed to reproduce the crash only if we tried to call "GetPropertyValue" when the application that is using the licensing library was not registered, i.e. it was in trial. Once the application was registered the exception disappeared and the value was correctly retrieved. The test was done in a Java application that is not using our java product launcher.

Is your application registered when you make the call to "GetPropertyValue"?

Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Hi,

We now tried calling "GetPropertyValue" using the licensing library that was registered. But still the same problem occurs.

Can you please share the source that you used for reproducing the issue, I will check my code against it, to verify if i am missing anything.

Thanks a ton for you support.

Regards,
Murugavel.R
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Hi,

It would be of great help if you can share me the source code.

Thanks,
Murugavel
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Load the licensing library to get license information :

Hi Murugavel,

Here is the sample code you need, the problem was with the function signature, as you can see in the code its different:

Code: Select all

public interface TrialLibrary extends Library { 
   final TrialLibrary INSTANCE = (TrialLibrary) Native.loadLibrary("C:\\Program Files (x86)\\Your Company\\Licensing\\lib",
                                 TrialLibrary.class); // loads Trial.dll 
   int ReadSettingsStr(String keyCode, HWND hwnd); 
   int DisplayRegistrationStr(String keyCode, HWND hwnd); 
   // String GetPropertyValue(String id); here is the problem the GetPropertyValue native method has a different signature 
   int GetPropertyValue(WString id, CharBuffer aBuffer, LongByReference len); // this is the solution 
 } 


private static final String LIBRARY_KEY = "43B10DE39332871B9AD8242FF81A7D44C081F0D7058BDEC4C177EC35194E53DA463777113BD3"; 

  public static void main(String[] args) { 
  // initialize the library 
  TrialLibrary.INSTANCE.ReadSettingsStr(LIBRARY_KEY, null); 

  WString id = new WString("ID"); 

  // retrieve the size of the property 
  LongByReference len = new LongByReference(0); 
  TrialLibrary.INSTANCE.GetPropertyValue(id, null, len); 

  // allocate buffer for property value 
  CharBuffer buffer = CharBuffer.allocate((int)len.getValue()); 

  // retrieve property value 
  TrialLibrary.INSTANCE.GetPropertyValue(new WString("ID"), buffer, len); 
  buffer.limit((int)len.getValue() - 1); 

  System.out.println(buffer.toString()); 
 }
Regards,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
murug86
Posts: 52
Joined: Mon May 21, 2012 10:59 am

Re: Load the licensing library to get license information :

Hi,

After changing the methods signature it worked.. Thanks a ton.

Regards,
Murugavel.R
Bogdan
Posts: 2796
Joined: Tue Jul 07, 2009 7:34 am
Contact: Website

Re: Load the licensing library to get license information :

Always a pleasure Murugavel.

Best of all,
Bogdan
Bogdan Mitrache - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”