• (2 Pages)
  • +
  • 1
  • 2

Using dll Library in java application using jacob illuststrate using dll libraries in java application Rate Topic: -----

#1 knowledgestudent  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 23-February 09

Posted 10 July 2009 - 01:58 PM

Hi all, I wanted to share you what I have learned about using dll libraries in java application using Jacob,

Introduction:
In this article I am going to demonstrate shortly, with a simple example, how to use dll libraries inside java applications, in order to test the sample program in this article you need to have at least jdk 5, the Jacob package API, also created dll file with complete knowledge of the structure of the library and its functions.
Attached is the sample code zipped with the Jacob jar file, the Com.dll file and the ReadDLL.java file that uses the Jacob.

“Dynamic link library” is Microsoft’s implementation of the shared library concepts in the Microsoft windows operating system. Dlls considered as a native application, not like any applications.
Using the dll libraries within the .Net framework is such an easy operation, just we need to load the library within the environment, initiate an object from it, then use it like any other object in the program.

Such an immediate operation does not exist for the java environment, so that there are some interfaces and frameworks has been built that allow java programmers to interact with dll libraries and use their functionality within java applications, such as the Jacob, “JACOB is a JAva-COm Bridge that allows you to call COM automation components from Java. It uses JNI internally to make native calls into COM and Win32 libraries. In simple words, you can now call any of the .dll file functions from Java and use the result in your Java program (provided you know which function to call)”, JNI is the Java Native Interface.

To start we need to:
• Load the jacob.dll file into the system path, described later,
• Register your dll file as Com, described later,
• Set the jacob jar file, within the class path of the project,
• Then start loading the Lib in the program, and using it.

Here in this article I am using a Com.dll that I have created using the Visual Studio .Net 2005 /VB, by the help of this article.
Creating Com dll using vs.2005
This Library is used simply to sum, subtract, multiply, and divide two integers passed to its methods, the first three return integers, and the last one return double.

Load the Jacob.dll file:
Just paste the Jacob.dll to the system path in your environment; in mine I have put it into the WINDOWS\System32 folder, some environments require a registration for the Jacob.dll using regsvr32 command.

Register the dll file “the Library”
To register the dll file, we use the “regasm /codebase” command from the Microsoft.Net either from the windows command prompt, or from the .Net command prompt itself as follows:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
The “v2.0.50727” may change from environment to another; you better search for the command to know the right path of it. In other words find the correct path of the regam.exe. you should expect to receive confirmation message that the file has been registered :
Microsoft ® .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright © Microsoft Corporation 1998-2004. All rights reserved.
Types registered successfully

Otherwise there must be something wrong with the building of the dll file, or some files are missing in the path of your system, [in case of some error, just google it, so that we are repeating].
To know more about the regasm command refer to: Assemply Registeration Tool

After registration, you are supposed to find the library loaded to the registry, you can check it to see the loaded Strong Library name, in our example it is: Com.Calculation
You can check the registry by the command: regedit from the Run.

Inside the java application:
To go with it, we need to have full description about the dll library we are using, in our example here; we have the description of the Com.Calculation Library as follows:
sum(int x,int y)
Div(int x, int y) // check if y = 0, returned as double
multi(int x, int y)
subtract(int x, int y)

Add the Jacob.jar file to your class path; the following is the code segments of needed operations for using the Library:


First load the library:
 //Loading the library:
		ActiveXComponent comp=new ActiveXComponent("Com.Calculation");		
		System.out.println("The Library been loaded, and an activeX component been created");

this may throw an exception (ComFailException: Can't get object clsid from progid) if the library is not registered, or not registered properly.

Then call the functions of the library:
 int summation=Dispatch.call(comp, "sum",arg1,arg2).toInt();
		 System.out.println("Summation= "+ summation);

		int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
		System.out.println("Subtraction= "+ subtraction);
		
		int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
		System.out.println("Multiplication= "+ multiplication);
		
		double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
		System.out.println("Division= "+ division);


using the Dispatch class that is from the jacb package, where the first argument is the component that we need to use its functions, the second is the function name as string, and then as many parameters you need to pass to the function, there are other variations. This may through an exception (ComFailException: Can't map name to dispid).

If some of the library functions (methods) return some kind of struct or a class of some type, then its properties could be accessed using the get method of the Dispatch Class:
Dispatch. get(object, “Property Name”);

it returns value with the data type specified.
Again you need to know the specification of the library.

The full ReadDLL.java follows:
package jacobtest;

import com.jacob.activeX.*;
import com.jacob.com.*;
/**
 * This class uses the the Jacob tech
 * to use and interact with a Com cmponent 
 * in a java application
 */
public class ReadDLL {   
	
	public static void main(String[] args){
		
		//Loading the library:
		ActiveXComponent comp=new ActiveXComponent("Com.Calculation");		
		System.out.println("The Library been loaded, and an activeX component been created");
		
		int arg1=100;
		int arg2=50;
		//using the functions from the library:		
		int summation=Dispatch.call(comp, "sum",arg1,arg2).toInt();
		System.out.println("Summation= "+ summation);
		
		int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
		System.out.println("Subtraction= "+ subtraction);
		
		int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
		System.out.println("Multiplication= "+ multiplication);
		
		double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
		System.out.println("Division= "+ division);
		
		/**The following code is abstract of using the get,
		 * when the library contains a function that return
		 * some kind of a struct, and then get its properties and values
		 **/
//		Dispatch disp=Dispatch.call(comp,"sum",100,10).toDispatch();
//		DataType Var=Dispatch.get(disp,"Property Name");
	}
}


The output of this simple program:
[font="Lucida Console"]The Library been loaded, and an activeX component been created
Summation= 150
Subtraction= 50
Multiplication= 5000
Division= 2.0

More details about Jacob solution:

Hope that this article helps to have a basic idea about using the jacob and save time for some people,
please if you have any question, feel free to contact me and ask!

Good Luck everybodyAttached File  Jacob_Test.zip (58.13K)
Number of downloads: 3504 :)

Is This A Good Question/Topic? 0
  • +

Replies To: Using dll Library in java application using jacob

#2 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Posted 12 July 2009 - 09:47 AM

Using the Jacob library seriously limits your code's portability but if your target platform is windows and you're hell bent on using Java, it's a good option.

Good Job. :^:
Was This Post Helpful? 0
  • +
  • -

#3 sharpener104  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-October 09

Posted 19 October 2009 - 06:20 AM

Hi, your article is very helpful indeed. I wonder if you could give me some light on how to use the system application component COMSVCS.TrackerServer with Jacob. I've been trying to create an instance of that component but I haven't been successful. The simple code " ActiveXComponent a = new ActiveXComponent("COMSVCS.TrackerServer"); " returns the following error:

Exception in thread "main" com.jacob.com.ComFailException: Can't QI object for IDispatch
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:101)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at app.Teste.main(Teste.java:20)

I'm new to Jacob and COM+ and I haven't a clue why this error occurs. Thanks in advance.
Was This Post Helpful? 0
  • +
  • -

#4 knowledgestudent  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 23-February 09

Posted 19 October 2009 - 12:43 PM

View Postsharpener104, on 19 Oct, 2009 - 05:20 AM, said:

Hi, your article is very helpful indeed. I wonder if you could give me some light on how to use the system application component COMSVCS.TrackerServer with Jacob. I've been trying to create an instance of that component but I haven't been successful. The simple code " ActiveXComponent a = new ActiveXComponent("COMSVCS.TrackerServer"); " returns the following error:

Exception in thread "main" com.jacob.com.ComFailException: Can't QI object for IDispatch
at com.jacob.com.Dispatch.createInstanceNative(Native Method)
at com.jacob.com.Dispatch.<init>(Dispatch.java:101)
at com.jacob.activeX.ActiveXComponent.<init>(ActiveXComponent.java:58)
at app.Teste.main(Teste.java:20)

I'm new to Jacob and COM+ and I haven't a clue why this error occurs. Thanks in advance.


Hi sharpener ,
I actually have not seen this exception before, but as I googled it, you need to know the exact functions of the "COMSVCS.TrackerServer' COM ,
but in all cases I can assume that it can not create an instance from the object type, so that you need to understand what this system application component do, then if you knew and got no specific issue you need to make sure that you have done all the process to get the jacob works,
in addition have tried some different COM, to test that there is no any problem with the system !!!
 at com.jacob.com.Dispatch.createInstanceNative(Native Method)
		at com.jacob.com.Dispatch.<init>(Dispatch.java:101)

as I can read from the exception that it can not create an instance and this could be from several reasons,

hope that help u even with thoughts , Good Luck with jacob,
jacob is noisy at the beginning but when u got it , it makes world easier :)
Was This Post Helpful? 0
  • +
  • -

#5 SaiKrishnaadivi  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-December 09

Posted 03 December 2009 - 08:36 AM

Hi

Your post is really helpful.I am a purely java developer.We never have .Net installed in our systems.Could you help me to register the com.dll.

I am getting the following error.
com.jacob.com.ComFailException: Can't get object clsid from progid when i tried to register the dll

ThankYou
Regards
Sai

View Postknowledgestudent, on 10 Jul, 2009 - 12:58 PM, said:

Hi all, I wanted to share you what I have learned about using dll libraries in java application using Jacob,

Introduction:
In this article I am going to demonstrate shortly, with a simple example, how to use dll libraries inside java applications, in order to test the sample program in this article you need to have at least jdk 5, the Jacob package API, also created dll file with complete knowledge of the structure of the library and its functions.
Attached is the sample code zipped with the Jacob jar file, the Com.dll file and the ReadDLL.java file that uses the Jacob.

“Dynamic link library” is Microsoft’s implementation of the shared library concepts in the Microsoft windows operating system. Dlls considered as a native application, not like any applications.
Using the dll libraries within the .Net framework is such an easy operation, just we need to load the library within the environment, initiate an object from it, then use it like any other object in the program.

Such an immediate operation does not exist for the java environment, so that there are some interfaces and frameworks has been built that allow java programmers to interact with dll libraries and use their functionality within java applications, such as the Jacob, “JACOB is a JAva-COm Bridge that allows you to call COM automation components from Java. It uses JNI internally to make native calls into COM and Win32 libraries. In simple words, you can now call any of the .dll file functions from Java and use the result in your Java program (provided you know which function to call)”, JNI is the Java Native Interface.

To start we need to:
• Load the jacob.dll file into the system path, described later,
• Register your dll file as Com, described later,
• Set the jacob jar file, within the class path of the project,
• Then start loading the Lib in the program, and using it.

Here in this article I am using a Com.dll that I have created using the Visual Studio .Net 2005 /VB, by the help of this article.
Creating Com dll using vs.2005
This Library is used simply to sum, subtract, multiply, and divide two integers passed to its methods, the first three return integers, and the last one return double.

Load the Jacob.dll file:
Just paste the Jacob.dll to the system path in your environment; in mine I have put it into the WINDOWS\System32 folder, some environments require a registration for the Jacob.dll using regsvr32 command.

Register the dll file “the Library”
To register the dll file, we use the “regasm /codebase” command from the Microsoft.Net either from the windows command prompt, or from the .Net command prompt itself as follows:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
The “v2.0.50727” may change from environment to another; you better search for the command to know the right path of it. In other words find the correct path of the regam.exe. you should expect to receive confirmation message that the file has been registered :
Microsoft ® .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright © Microsoft Corporation 1998-2004. All rights reserved.
Types registered successfully

Otherwise there must be something wrong with the building of the dll file, or some files are missing in the path of your system, [in case of some error, just google it, so that we are repeating].
To know more about the regasm command refer to: Assemply Registeration Tool

After registration, you are supposed to find the library loaded to the registry, you can check it to see the loaded Strong Library name, in our example it is: Com.Calculation
You can check the registry by the command: regedit from the Run.

Inside the java application:
To go with it, we need to have full description about the dll library we are using, in our example here; we have the description of the Com.Calculation Library as follows:
sum(int x,int y)
Div(int x, int y) // check if y = 0, returned as double
multi(int x, int y)
subtract(int x, int y)

Add the Jacob.jar file to your class path; the following is the code segments of needed operations for using the Library:


First load the library:
 //Loading the library:
		ActiveXComponent comp=new ActiveXComponent("Com.Calculation");		
		System.out.println("The Library been loaded, and an activeX component been created");

this may throw an exception (ComFailException: Can't get object clsid from progid) if the library is not registered, or not registered properly.

Then call the functions of the library:
 int summation=Dispatch.call(comp, "sum",arg1,arg2).toInt();
		 System.out.println("Summation= "+ summation);

		int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
		System.out.println("Subtraction= "+ subtraction);
		
		int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
		System.out.println("Multiplication= "+ multiplication);
		
		double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
		System.out.println("Division= "+ division);


using the Dispatch class that is from the jacb package, where the first argument is the component that we need to use its functions, the second is the function name as string, and then as many parameters you need to pass to the function, there are other variations. This may through an exception (ComFailException: Can't map name to dispid).

If some of the library functions (methods) return some kind of struct or a class of some type, then its properties could be accessed using the get method of the Dispatch Class:
Dispatch. get(object, “Property Name”);

it returns value with the data type specified.
Again you need to know the specification of the library.

The full ReadDLL.java follows:
package jacobtest;

import com.jacob.activeX.*;
import com.jacob.com.*;
/**
 * This class uses the the Jacob tech
 * to use and interact with a Com cmponent 
 * in a java application
 */
public class ReadDLL {   
	
	public static void main(String[] args){
		
		//Loading the library:
		ActiveXComponent comp=new ActiveXComponent("Com.Calculation");		
		System.out.println("The Library been loaded, and an activeX component been created");
		
		int arg1=100;
		int arg2=50;
		//using the functions from the library:		
		int summation=Dispatch.call(comp, "sum",arg1,arg2).toInt();
		System.out.println("Summation= "+ summation);
		
		int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
		System.out.println("Subtraction= "+ subtraction);
		
		int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
		System.out.println("Multiplication= "+ multiplication);
		
		double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
		System.out.println("Division= "+ division);
		
		/**The following code is abstract of using the get,
		 * when the library contains a function that return
		 * some kind of a struct, and then get its properties and values
		 **/
//		Dispatch disp=Dispatch.call(comp,"sum",100,10).toDispatch();
//		DataType Var=Dispatch.get(disp,"Property Name");
	}
}


The output of this simple program:
[font="Lucida Console"]The Library been loaded, and an activeX component been created
Summation= 150
Subtraction= 50
Multiplication= 5000
Division= 2.0

More details about Jacob solution:

Hope that this article helps to have a basic idea about using the jacob and save time for some people,
please if you have any question, feel free to contact me and ask!

Good Luck everybodyAttachment attachment :)

Was This Post Helpful? 0
  • +
  • -

#6 knowledgestudent  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 23-February 09

Posted 03 December 2009 - 02:07 PM

Hi, I am glad that the article is helping,
I would like to answer ur Q, but I need to know if you followed the steps in the post,
in addition this exception occurs when u did what??

hope it will work with,

Regards,
there is always sol'n


View PostSaiKrishnaadivi, on 3 Dec, 2009 - 07:36 AM, said:

Hi

Your post is really helpful.I am a purely java developer.We never have .Net installed in our systems.Could you help me to register the com.dll.

I am getting the following error.
com.jacob.com.ComFailException: Can't get object clsid from progid when i tried to register the dll

ThankYou
Regards
Sai

View Postknowledgestudent, on 10 Jul, 2009 - 12:58 PM, said:

Hi all, I wanted to share you what I have learned about using dll libraries in java application using Jacob,

Introduction:
In this article I am going to demonstrate shortly, with a simple example, how to use dll libraries inside java applications, in order to test the sample program in this article you need to have at least jdk 5, the Jacob package API, also created dll file with complete knowledge of the structure of the library and its functions.
Attached is the sample code zipped with the Jacob jar file, the Com.dll file and the ReadDLL.java file that uses the Jacob.

“Dynamic link library” is Microsoft’s implementation of the shared library concepts in the Microsoft windows operating system. Dlls considered as a native application, not like any applications.
Using the dll libraries within the .Net framework is such an easy operation, just we need to load the library within the environment, initiate an object from it, then use it like any other object in the program.

Such an immediate operation does not exist for the java environment, so that there are some interfaces and frameworks has been built that allow java programmers to interact with dll libraries and use their functionality within java applications, such as the Jacob, “JACOB is a JAva-COm Bridge that allows you to call COM automation components from Java. It uses JNI internally to make native calls into COM and Win32 libraries. In simple words, you can now call any of the .dll file functions from Java and use the result in your Java program (provided you know which function to call)”, JNI is the Java Native Interface.

To start we need to:
• Load the jacob.dll file into the system path, described later,
• Register your dll file as Com, described later,
• Set the jacob jar file, within the class path of the project,
• Then start loading the Lib in the program, and using it.

Here in this article I am using a Com.dll that I have created using the Visual Studio .Net 2005 /VB, by the help of this article.
Creating Com dll using vs.2005
This Library is used simply to sum, subtract, multiply, and divide two integers passed to its methods, the first three return integers, and the last one return double.

Load the Jacob.dll file:
Just paste the Jacob.dll to the system path in your environment; in mine I have put it into the WINDOWS\System32 folder, some environments require a registration for the Jacob.dll using regsvr32 command.

Register the dll file “the Library”
To register the dll file, we use the “regasm /codebase” command from the Microsoft.Net either from the windows command prompt, or from the .Net command prompt itself as follows:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
The “v2.0.50727” may change from environment to another; you better search for the command to know the right path of it. In other words find the correct path of the regam.exe. you should expect to receive confirmation message that the file has been registered :
Microsoft ® .NET Framework Assembly Registration Utility 2.0.50727.42
Copyright © Microsoft Corporation 1998-2004. All rights reserved.
Types registered successfully

Otherwise there must be something wrong with the building of the dll file, or some files are missing in the path of your system, [in case of some error, just google it, so that we are repeating].
To know more about the regasm command refer to: Assemply Registeration Tool

After registration, you are supposed to find the library loaded to the registry, you can check it to see the loaded Strong Library name, in our example it is: Com.Calculation
You can check the registry by the command: regedit from the Run.

Inside the java application:
To go with it, we need to have full description about the dll library we are using, in our example here; we have the description of the Com.Calculation Library as follows:
sum(int x,int y)
Div(int x, int y) // check if y = 0, returned as double
multi(int x, int y)
subtract(int x, int y)

Add the Jacob.jar file to your class path; the following is the code segments of needed operations for using the Library:


First load the library:
 //Loading the library:
		ActiveXComponent comp=new ActiveXComponent("Com.Calculation");		
		System.out.println("The Library been loaded, and an activeX component been created");

this may throw an exception (ComFailException: Can't get object clsid from progid) if the library is not registered, or not registered properly.

Then call the functions of the library:
 int summation=Dispatch.call(comp, "sum",arg1,arg2).toInt();
		 System.out.println("Summation= "+ summation);

		int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
		System.out.println("Subtraction= "+ subtraction);
		
		int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
		System.out.println("Multiplication= "+ multiplication);
		
		double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
		System.out.println("Division= "+ division);


using the Dispatch class that is from the jacb package, where the first argument is the component that we need to use its functions, the second is the function name as string, and then as many parameters you need to pass to the function, there are other variations. This may through an exception (ComFailException: Can't map name to dispid).

If some of the library functions (methods) return some kind of struct or a class of some type, then its properties could be accessed using the get method of the Dispatch Class:
Dispatch. get(object, “Property Name”);

it returns value with the data type specified.
Again you need to know the specification of the library.

The full ReadDLL.java follows:
package jacobtest;

import com.jacob.activeX.*;
import com.jacob.com.*;
/**
 * This class uses the the Jacob tech
 * to use and interact with a Com cmponent 
 * in a java application
 */
public class ReadDLL {   
	
	public static void main(String[] args){
		
		//Loading the library:
		ActiveXComponent comp=new ActiveXComponent("Com.Calculation");		
		System.out.println("The Library been loaded, and an activeX component been created");
		
		int arg1=100;
		int arg2=50;
		//using the functions from the library:		
		int summation=Dispatch.call(comp, "sum",arg1,arg2).toInt();
		System.out.println("Summation= "+ summation);
		
		int subtraction= Dispatch.call(comp,"subtract",arg1,arg2).toInt();
		System.out.println("Subtraction= "+ subtraction);
		
		int multiplication=Dispatch.call(comp,"multi",arg1,arg2).toInt();
		System.out.println("Multiplication= "+ multiplication);
		
		double division=Dispatch.call(comp,"div",arg1,arg2).toDouble();
		System.out.println("Division= "+ division);
		
		/**The following code is abstract of using the get,
		 * when the library contains a function that return
		 * some kind of a struct, and then get its properties and values
		 **/
//		Dispatch disp=Dispatch.call(comp,"sum",100,10).toDispatch();
//		DataType Var=Dispatch.get(disp,"Property Name");
	}
}


The output of this simple program:
[font="Lucida Console"]The Library been loaded, and an activeX component been created
Summation= 150
Subtraction= 50
Multiplication= 5000
Division= 2.0

More details about Jacob solution:

Hope that this article helps to have a basic idea about using the jacob and save time for some people,
please if you have any question, feel free to contact me and ask!

Good Luck everybodyAttachment attachment :)

Was This Post Helpful? 0
  • +
  • -

#7 credics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-February 10

Posted 03 February 2010 - 03:13 AM

knowledgestudent:

Thanks for the explanation. It was very helpful.

I have one question though -

If in your example you had an inner component/class (inside com.calculation) and you wanted to use this inner component/class (e.i. use one of its attributes or one of its members), how would you access this inner component?


If my question is not clear, here's something more elaborated -
In your example, you used the methods "div/multi/subtract/sum" which are located right under com.calculation. But what if, beside these methods there was some component/object and inside of it there was a an attribute. How would you get to this attribute?
I guess it was something similar to Dispatch.call(comp,"multi",arg1,arg2). But what if instead of arg1 you needed to use the attribute from the "inner" component/object?


Thanks A LOT

Ofir
Was This Post Helpful? 0
  • +
  • -

#8 knowledgestudent  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 23-February 09

Posted 03 February 2010 - 05:48 AM

Hello Ofir,
I guess this is interseting, but the only way to know for sure is to try it,

But what I do not get is: how will the class be inner, then I will use one of its attributes from out side ( in the java) !!

may be if u illustrate more real scenario it will be clearer,

I think it would be better to access the needed attributes by get Methods , may be at that point u will be able to use them as args in the call, (as in ur example) after u have getton them by some method,

I donno if I helpt, but again if u have a clearer example ( real) then may be we can come up with some solution

Best Regards,


View Postcredics, on 03 February 2010 - 02:13 AM, said:

knowledgestudent:

Thanks for the explanation. It was very helpful.

I have one question though -

If in your example you had an inner component/class (inside com.calculation) and you wanted to use this inner component/class (e.i. use one of its attributes or one of its members), how would you access this inner component?


If my question is not clear, here's something more elaborated -
In your example, you used the methods "div/multi/subtract/sum" which are located right under com.calculation. But what if, beside these methods there was some component/object and inside of it there was a an attribute. How would you get to this attribute?
I guess it was something similar to Dispatch.call(comp,"multi",arg1,arg2). But what if instead of arg1 you needed to use the attribute from the "inner" component/object?


Thanks A LOT

Ofir

Was This Post Helpful? 0
  • +
  • -

#9 credics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-February 10

Posted 03 February 2010 - 06:37 AM

Thanks for your immediate reply...


I'll now try to give you a real example - now I'll go down to details and use the elements in your example:


In the Com.Calculation, the hierarchy is as follow - "Com" and under it u have the "Calculation" and under it u have (1.) "Base Types" and (2.) the methods 'div', 'multi', 'subtract' and 'sum'.
Now, as you explained, in order to use the method "sum" you used the following -
ActiveXComponent comp=new ActiveXComponent("Com.Calculation");
and then
Dispatch.call(comp, "sum",arg1,arg2).toInt(); // By this command you were able to use the method 'sum'.


Say the hierarchy in Com.Calculation, u also had an element, called "xxx", that contains fields, called "A", "B" and "C" of type "xxx". (see attachment).

Now I want to use "A" field (of type "xxx"):
Suppose that I want to send the method "sum" the parameter "A" (of type "xxx") and some String - something like this -
Dispatch.call(comp, "sum", A, someString).toInt();


What I didn't manage to do was to reach the field A and use it as a parameter in "sum" method. (the method I need to use requires a parameter of type "xxx")

I tried getProperty / get method to no avail...


If u can help me with that, I would appreciate it a lot.

Thanks

Ofir

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#10 zubin.polra2007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-February 10

Posted 03 February 2010 - 10:26 PM

it is not working within servlet..because as i think ,servlet is executed as thread




i am using this line in servlet

ActiveXComponent comp = new ActiveXComponent("MTaxSum_DAL.Form16_TaxCalculation");

This line executes once after each startup of Application server(GlassFish,TomCat). On second time it raise exception. Exception is:Native Library C:\zubin\jacob.dll already loaded in another classloader.
we need to restart server..

Why??

This post has been edited by zubin.polra2007: 04 February 2010 - 02:05 AM

Was This Post Helpful? 0
  • +
  • -

#11 knowledgestudent  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 46
  • Joined: 23-February 09

Posted 04 February 2010 - 01:41 PM

hello Ofir,
now I get the idea , I hope :)

as I understood, the element 'xxx' will be type of another class, isn't it ?,
if so, and it is a type of ur own, maybe it will be helpful to have a special methods to get the values of the fields A, B ....

or even add some methods to get the value of those filed from inside this class (the computation class),
let me illustrate more,

u will need to add a method named "get_A" for example, which returns the value stored in A, ( I am talking inside the calculation class itself)

then call it, from the java, by using:
v_a = Dispatch.call(comp, "get_A" // or what ever is ur field

then use v_a in the call of the "sum" method,

hope I made the idea clear,
in short, it could be solved by the idea of encapsulation, when u r in java u will be able to use any thing from the .net class, by dispatching methods defined in the .net class, so any element u need to get , u need a method inside the class to return it, u can not just use it immediately inside the java.

hope this helps, please try it and let me know if there still some issues not clear or not set properly.

Best Regards,

HEllo,
actually I am not familiar with servlet, or jacob from servlet, but the exception seems not because of the statement, but it is related of to loading, maybe some thing in the loading or starting the service,

sorry for not helping, but I actually do not have good idea about it.
Regards,

View Postzubin.polra2007, on 03 February 2010 - 09:26 PM, said:

it is not working within servlet..because as i think ,servlet is executed as thread




i am using this line in servlet

ActiveXComponent comp = new ActiveXComponent("MTaxSum_DAL.Form16_TaxCalculation");

This line executes once after each startup of Application server(GlassFish,TomCat). On second time it raise exception. Exception is:Native Library C:\zubin\jacob.dll already loaded in another classloader.
we need to restart server..

Why??

Was This Post Helpful? 0
  • +
  • -

#12 credics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-February 10

Posted 07 February 2010 - 01:19 AM

knowledgestudent,

You understood correctly... I still have some problems with this scenario, but I guess its only me from now on....

Thanks a lot for you efforts, you did help me.
Ofir
Was This Post Helpful? 0
  • +
  • -

#13 credics  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 03-February 10

Posted 07 February 2010 - 08:33 AM

knowledgestudent,


One more question...

I hope this post relates to the subject of this forum...



I use the JAVA language and I call a method that returns its answer by 'by reference'.
For example (I use your example) -
int multiplication = Dispatch.call(comp,"multi",arg1,arg2)
the method "multi" receives 2 parameters - arg1 and arg2 and its return value is in multiplication variable.

Suppose the method "multi" puts its return value in arg2.
Meaning the arg2 I sent the method "multi" was sent by reference. Do u know how I retrieve the return value from arg2???

Because, in my problem, the argument arg2's value stays as it was before I sent it to "multi". The answer "multi" calculated, is not in arg2..

Any ideas???


Thanks
Ofir
Was This Post Helpful? 0
  • +
  • -

#14 Guest_Asha*


Reputation:

Posted 09 February 2010 - 12:01 AM

View Postcredics, on 07 February 2010 - 07:33 AM, said:

knowledgestudent,


One more question...

I hope this post relates to the subject of this forum...



I use the JAVA language and I call a method that returns its answer by 'by reference'.
For example (I use your example) -
int multiplication = Dispatch.call(comp,"multi",arg1,arg2)
the method "multi" receives 2 parameters - arg1 and arg2 and its return value is in multiplication variable.

Suppose the method "multi" puts its return value in arg2.
Meaning the arg2 I sent the method "multi" was sent by reference. Do u know how I retrieve the return value from arg2???

Because, in my problem, the argument arg2's value stays as it was before I sent it to "multi". The answer "multi" calculated, is not in arg2..

Any ideas???


Thanks
Ofir

Was This Post Helpful? 0

#15 Guest_Asha*


Reputation:

Posted 09 February 2010 - 12:13 AM

Hi,

I could not find a Jacob developer documentation anywhere so far. And this article gave me little hope. I thought probably you can answer to my question. As I couldn't figure out how to post my question here, I am posting it as a reply to this article.
I need to convert a macro in VB something like what I pasted below in to Java using Jacob.

With Selection.Find
.Text = "Author"
.Replacement.Text = "Author Name"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With

I don't know how to set the property Replacement.Text. And also how to implement this construct With... End With using Jacob.
Kindly let me know what API to refer or point me to some useful resources on the net where I can find some documentation for beginners on how to use Jacob.

Thank you in advance.

Asha.
Was This Post Helpful? 1

  • (2 Pages)
  • +
  • 1
  • 2