Accessing VB Code using JNI
Can access functions implemented in Visual Basic from a Java program using JNI?
I was thinking like, since there's no .h file concept in VB, we can't access VB code from Java. Correct me if i am wrong....
Thanks,
Vasu
As long as the VB app somehow exports its functions via the standard "C" interface (which is how all DLLs are exported), then you can call into it via JNI. I've successfully used JNI to call into a Delphi DLL, for example.
The hard part is that VB doesn't want to do this by default, and to be honest, I'm not enough of a VB expert to tell you how you could do this. You can check your success, however, by running the dumpbin.exe utility (comes with MSVC) on the compiled DLL and see if your method shows up in some form. Once you know that name and how the parameters look (by-ref or by-val), you should be in good shape.
I won't say it's an easy road to go, however--you may have more luck just hosting the VB code as an ActiveX control and connecting to it via the higher-level Java->COM APIs. Stu Halloway has a collection of such links on his home page: http://staff.develop.com/halloway.
Similar Messages
-
Deploying a WAR file containing .jsp and servlets (also uses JNI)
Deploying a WAR file containing .jsp and servlets (also uses JNI) on Windows 2000
We had problems making it initially work on Sun ONE Web Server 6.0 Service Pack 1 because of lack of good iPlanet Web
Server documentation on deploying such files.
This is how we went about it:
1) Make one of the servlet and JSP (must call another Java Class) web application (.war) examples work with iPlanet Web
Server.
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\HelloWorld\HelloWorld.war
and
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
a) Go to your Web Server Administration to deploy the application using GUI Web Application Deploy.
(We usually use command line, we experienced some issues with the GUI version, but maybe it is fixed in the new Web Server
service packs)
From browser, open http://yourserver:8888/
Click on Select a Server:Manage
Click on Virtual Server Class
Click on https-yourserver
Click on the Web Applications Tab
Then, click on Deploy Web Application
Enter the following -
WAR File On: Local
WAR File Path: C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Application URI: /jakarta
Installation Directory: c:\iPlanet\examples\jakarta-examples
By clicking on OK it deployed the application.
I can verify that it is deployed by selecting "Edit Web Applications" and I see the following entry:
Edit /jakarta c:/iPlanet/examples/jakarta-examples
Also, c:/iPlanet/examples/jakarta-examples should have the similar following directory structure ..
- [images]
- [jsp]
- index.html
- [servlets]
- [META-INF]
- [WEB-INF]
- [classes]
- [tlds]
- web.xml
- index.html
I restarted the server and accessed it using the following URL from my IE browser:
http://yourserver/jakarta/index.html
Then I clicked on the JSP Examples and tried some JSP examples.
b) Alternatively, you can also deploy the same example from the command-line.
Make sure C:\iPlanet\Servers\bin\https\httpadmin\bin\ is in your path
wdeploy deploy -u /jakarta
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\jakarta-examples
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Restart the web server (I don't think you have to restart, but .. might as well).
2)Deploy your web-application
My Foo.war has the following structure.
You can use jar tf Foo.war to look at the file contents from command line (assuming you have JDK installed and the bin is
in your PATH)
Foo.war
- [META-INF]
- [WEB-INF]
- web.xml
- [classes]
- Bar.class
- MoServlet.class
- [lib]
- ThirdParty.jar
- [natlib]
- extlib.dll
- foo.jsp
Here is our application scenario:
foo.jsp uses a class call Bar (it is not in any package). The Bar java class uses classes from ThirdParty.jar. The
ThirdParty.jar in turn uses JNI to load library extlib.dll. foo.jsp also calls /servlet/Mo as well.
Now to deploy it, do the following:
(a) Make sure that within foo.jsp, you import the Bar class ( I don't know why you have to do it, but if you don't you get
JSP compile error).
<%@page language="java" import="Bar" contentType="text/html"%>
(b) Check web.xml (for Servlets)
Within web.xml, make sure you have the following mappings:
<servlet>
<servlet-name> MoLink </servlet-name>
<servlet-class> MoServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> MoLink </servlet-name>
<url-pattern> /servlet/Mo </url-pattern>
</servlet-mapping>
(c) Deploy the application
Using command line:
wdeploy deploy -u /foo
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\foo-dir
Foo.war
(d) Change web-apps.xml file (for picking up ThirdParty.jar)
It is located in
C:\iPlanet\Servers\https-yourserver\config
You should see something similar to following after successful deployment.
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true"/>
Change it to look like following to pick up the ThirdParty.jar
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true">
<class-loader reload-interval="300"
classpath="C:/iPlanet/examples/foo-dir/WEB-INF/lib/ThirdParty.jar"
delegate="false"/>
</web-app>
(e) Change jvm12.conf file (for JNI)
It is located in
C:\iPlanet\Servers\https-yourserver\config
Add or uncomment the following lines:
#optional - just helps with instrumenting the jsp and servlet code
jvm.include.CLASSPATH=1
jvm.enableDebug=1
nes.jsp.enabledebug=1
jvm.trace=7
jvm.verboseMode=1
#required for JNI
java.compiler=NONE
jvm.classpath=.;C:\JDK1.3.1\lib\tools.jar;C:/iPlanet/Servers/plugins/servlets/examples/legacy/beans.10/SDKBeans10.jar;
jvm.option=-Xrs
jvm.option=-Xnoagent
# not sure if this is needed for iPlanet web server
jvm.option=-Djava.library.path=C:/iPlanet/examples/foo-dir/natlib/ -Djava.compiler=NONE
(f) Change magnus.conf file (for JNI)
We HAD to change this file in order for ThirdParty.jar file to pick up the native C++ code using JNI. Apparently, the
iPlanet Web Server doesn't pick the Environment Variable Path. Because when we had the directory containing the DLL just
in Path, it didn't work.
Change Extrapath directive:
ExtraPath C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
to
ExtraPath c:/iPlanet/examples/foo-dir/natlib;C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
(g) Apply changes from the Web Server Administration Console and Restart the web server.
You should be able to see the behaviour that you want from your application.
http://yourserver/foo/foo.jsp
Hope this was helpful!!!
SonuDeploying a WAR file containing .jsp and servlets (also uses JNI) on Windows 2000
We had problems making it initially work on Sun ONE Web Server 6.0 Service Pack 1 because of lack of good iPlanet Web
Server documentation on deploying such files.
This is how we went about it:
1) Make one of the servlet and JSP (must call another Java Class) web application (.war) examples work with iPlanet Web
Server.
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\HelloWorld\HelloWorld.war
and
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
a) Go to your Web Server Administration to deploy the application using GUI Web Application Deploy.
(We usually use command line, we experienced some issues with the GUI version, but maybe it is fixed in the new Web Server
service packs)
From browser, open http://yourserver:8888/
Click on Select a Server:Manage
Click on Virtual Server Class
Click on https-yourserver
Click on the Web Applications Tab
Then, click on Deploy Web Application
Enter the following -
WAR File On: Local
WAR File Path: C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Application URI: /jakarta
Installation Directory: c:\iPlanet\examples\jakarta-examples
By clicking on OK it deployed the application.
I can verify that it is deployed by selecting "Edit Web Applications" and I see the following entry:
Edit /jakarta c:/iPlanet/examples/jakarta-examples
Also, c:/iPlanet/examples/jakarta-examples should have the similar following directory structure ..
- [images]
- [jsp]
- index.html
- [servlets]
- [META-INF]
- [WEB-INF]
- [classes]
- [tlds]
- web.xml
- index.html
I restarted the server and accessed it using the following URL from my IE browser:
http://yourserver/jakarta/index.html
Then I clicked on the JSP Examples and tried some JSP examples.
b) Alternatively, you can also deploy the same example from the command-line.
Make sure C:\iPlanet\Servers\bin\https\httpadmin\bin\ is in your path
wdeploy deploy -u /jakarta
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\jakarta-examples
C:\iPlanet\Servers\plugins\servlets\examples\web-apps\jakarta-examples\jarkarta-examples.war
Restart the web server (I don't think you have to restart, but .. might as well).
2)Deploy your web-application
My Foo.war has the following structure.
You can use jar tf Foo.war to look at the file contents from command line (assuming you have JDK installed and the bin is
in your PATH)
Foo.war
- [META-INF]
- [WEB-INF]
- web.xml
- [classes]
- Bar.class
- MoServlet.class
- [lib]
- ThirdParty.jar
- [natlib]
- extlib.dll
- foo.jsp
Here is our application scenario:
foo.jsp uses a class call Bar (it is not in any package). The Bar java class uses classes from ThirdParty.jar. The
ThirdParty.jar in turn uses JNI to load library extlib.dll. foo.jsp also calls /servlet/Mo as well.
Now to deploy it, do the following:
(a) Make sure that within foo.jsp, you import the Bar class ( I don't know why you have to do it, but if you don't you get
JSP compile error).
<%@page language="java" import="Bar" contentType="text/html"%>
(b) Check web.xml (for Servlets)
Within web.xml, make sure you have the following mappings:
<servlet>
<servlet-name> MoLink </servlet-name>
<servlet-class> MoServlet </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> MoLink </servlet-name>
<url-pattern> /servlet/Mo </url-pattern>
</servlet-mapping>
(c) Deploy the application
Using command line:
wdeploy deploy -u /foo
-i yourserver
-v https-yourserver
-d c:\iplanet\examples\foo-dir
Foo.war
(d) Change web-apps.xml file (for picking up ThirdParty.jar)
It is located in
C:\iPlanet\Servers\https-yourserver\config
You should see something similar to following after successful deployment.
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true"/>
Change it to look like following to pick up the ThirdParty.jar
<web-app uri="/foo" dir="C:\iPlanet\examples\foo-dir" enable="true">
<class-loader reload-interval="300"
classpath="C:/iPlanet/examples/foo-dir/WEB-INF/lib/ThirdParty.jar"
delegate="false"/>
</web-app>
(e) Change jvm12.conf file (for JNI)
It is located in
C:\iPlanet\Servers\https-yourserver\config
Add or uncomment the following lines:
#optional - just helps with instrumenting the jsp and servlet code
jvm.include.CLASSPATH=1
jvm.enableDebug=1
nes.jsp.enabledebug=1
jvm.trace=7
jvm.verboseMode=1
#required for JNI
java.compiler=NONE
jvm.classpath=.;C:\JDK1.3.1\lib\tools.jar;C:/iPlanet/Servers/plugins/servlets/examples/legacy/beans.10/SDKBeans10.jar;
jvm.option=-Xrs
jvm.option=-Xnoagent
# not sure if this is needed for iPlanet web server
jvm.option=-Djava.library.path=C:/iPlanet/examples/foo-dir/natlib/ -Djava.compiler=NONE
(f) Change magnus.conf file (for JNI)
We HAD to change this file in order for ThirdParty.jar file to pick up the native C++ code using JNI. Apparently, the
iPlanet Web Server doesn't pick the Environment Variable Path. Because when we had the directory containing the DLL just
in Path, it didn't work.
Change Extrapath directive:
ExtraPath C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
to
ExtraPath c:/iPlanet/examples/foo-dir/natlib;C:/iPlanet/Servers/bin/https/bin;${NSES_JRE_RUNTIME_LIBPATH}
(g) Apply changes from the Web Server Administration Console and Restart the web server.
You should be able to see the behaviour that you want from your application.
http://yourserver/foo/foo.jsp
Hope this was helpful!!!
Sonu -
Hi
i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
Can some one show me a sample code using JNI with Servlets.
thanks very muchJNI is done in servlets that same way as other java.
I suspect your problem is in the environment and perhaps how servlets work. It doesn't have anything to do with JNI itself. -
Hi
i was trying to do some example with JNI. I can use JNI with standalone Java application but I just cannot figure out how I can use JNI with Servlet.
Can some one show me a sample code using JNI with Servlets.
thanks very muchhi,
I am also facing the same problem,
when I am using JNI with stand alone application it works fine but when i tried to use it with a servlet It gives unsatisfied linker error
stack: java.lang.UnsatisfiedLinkError: createSocket
at RelayConnector.createSocket(Native Method)
at RelayServlet.doGet(RelayServlet.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:891)
at com.iplanet.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:458)
It seems i have to do some path settings in my iplenet web server.
If some one have faced the problem i would be glad to know the solution for this, i am literally bugged up,.... -
Management of large projects using JNI
I've got some code written in C and I want to interact with these code using JNI. But these code comprehends lots of c and h files, spreaded in lots of directories. To compile all of these, I have some makefiles. My question is: how can I start managing all of these code using JNI, I mean, what could it be my start point? Should I try to change the c code that calls everything?
Where can I put my new generated java, c and h files, in order not to generate a great mess?
Thanks!
GilmarWhere can I put my new generated java, c and h files,
in order not to generate a great mess?In a directory besides the one that contains all of your other C/H code. -
How to instantiate a java object (using JNI)?(n'more)
hey bschauwe, thanks for your last post, you were guessing but your 4th guess was right on the money of how id like to do it.
"4. An alternative way to return data to java from C is to instantiate a java object (using JNI), then use JNI to call that object's setters, then return the object at the end of the C routine."
I know now how to get the object's setters, I am just unsure how to instantiate a java object from the native C code using JNI. Also you said to returnt he object at the end of the c routine, that is just a good ol' return statement right? no other functions to release memory or anything are needed? So basically it would be something like:
JNIEXPORT jobject retObj JNICALL Java_AbfaRegion_getJSourceData
(JNIEnv *env, jobject thisObj)
//instantiate the java object on retObj????
//call setters with values from the c structures...
//return retObj??? no other memory releasing needed?
}Thanks again for all your help,
ShaneK sounds straight forward enough, the index in my book had nothing on <init> and I wasnt aware of the NewObject call. So my final (well for demonstration purposes) code should look something like:
JNIEXPORT jobject retObj JNICALL Java_AbfaRegion_getJSourceData
(JNIEnv *env, jobject thisObj)
jclass clazz;
jclass clazzTemp;
jmethodID mid;
jint val;
jobject tempObj;
//first instanciate the object
clazz = (*env)->GetObjectClass(env, retObj);
mid = (*env)->GetMethodID(env, clazz, "<init>", "()V");
//Get Object
tempObj = (*env)->NewObject(env, clazz, mid);
//get Class reference to instantiated class
clazzTemp = (*env)->GetObjectClass(env, tempObj);
//Start calling setters to set the object up.
mid = (*env)->GetMethodID(env, clazzTemp, "SetHeight", "(I)V");
(*env)->CallVoidMethod(env,tempObj, mid, struct->myHeight);
//set more members ...
//return the object back to java with its members filled out.
//before returning do I need to call (*env)->DeleteLocalRef(tempObj); ??
return tempObj;
}So is this how i do it for a function that is nativly defined as:
public native JSources getJSourceData();?
if this is right, then im cooking, and cannot thank you enough!
-Shane -
hi all
i need to implement this line from native code using JNI:
FileInputStream fileinputstream = new FileInputStream(filename);
ObjectInputStream objectinputstream = new ObjectInputStream(fileinputstream);
LogEventObject Line;
Line = (LogEventObject)objectinputstream.readObject();
...readObject() returns null
i think this is because readObject() checks type conversion (LogEventObject), but how can i implement this from my native code?
p.s. code works from java w\o any probsi need to implement this line from native code using JNI:Why? Why not do it at the Java level?
FileInputStream fileinputstream = new FileInputStream(filename);
ObjectInputStream objectinputstream = new ObjectInputStream(fileinputstream);
LogEventObject Line;
Line = (LogEventObject)objectinputstream.readObject();
...readObject() returns nullThat can only be because somebody wrote a null to the corresponding object output stream.
i think this is because readObject() checks type conversion (LogEventObject)No it doesn't, so it isn't because of that at all. readObject() can't even see that cast. The only way you can get a null from readObject() is if there is a null there waiting to be read. Or, in JNI, if there is a pending exception that you are ignoring, which is the most likely explanation.
p.s. code works from java w\o any probsMoral: don't write anything in JNI that you could write in Java. -
Can I access BIOS using JNI?
Hi,
Can I access BIOS using JNI on Windows and Linux platforms?
MathewI guess that the old BIOS functions (INT 15 for instance) are "emulated" by Windows when you are running old 16-bit DOS programs. They're mapped into equivalent Windows calls. Even if the BIOS implement different features you can't run the exact BIOS code. (Please correct me if I'm wrong)
I don't know about Linux handling of BIOS calls.
If you simply want to read (not execute) the BIOS code in Linux you can use a special device (/dev/kmem? I can't remember the exact name) and seek to the BIOS address. -
Access object attributes using other object JNI native method
Hi. I'm trying to change an attribute of object O1 from another object O2 without invoking a O1 method and without making the attribute as public or protected.
The only possibility that comes to my mind for doing so is writting a JNI native method
public class O1 {
static public native changeAttribute (Object O2, Object newAttributeValue) ;
that change the attribute memory reference, but all I've found about accesing attributes in JNI is about accessing the invoker attributes (in this case, O1).
�Does any one know if it's possible to do so? Thanks.I know that is not a good practice but I cannot figure out another way.
I'll try to explain the whole problem so you see the reason. I'm working with transactions, using objects as the data. An object can be opened for write by several transactions because the granularity for conflicts is not the object, is each of its attributes. As long as two transaction don't write the same attribute, they both can write. For writing, each transactions uses a private copy of the object. At committing, the actual copy of the object must be replaced by the committer one, but as far as the granularity is the object attributes, only each written attribute must be replaced (if not, only the last commit would be visible).
This attribute replace must be done by the transaction manager as far as the transactional object is provided by the client. So what i was thinking was to use JNI or some trick like that to replace the object attributes transparently to the object.
I hope the explain is clear, my english is a little asleep :-(.
How to do it with reflection? I thought that was only for method calling. Anyway, there wouldn't be problems if the attributes are private?
Thanks for answering.
EDIT: I've been able to change a public field using reflection, but not the private one
import java.lang.reflect.*;
class Caca {
public static void main(String[] args) {
Integer r = new Integer(0);
System.out.println("original: " + r.toString());
modifyWidth(r, 300);
System.out.println("modified: " + r.toString());
static void modifyWidth(Integer r, int newValue ) {
Field valueField; Class c = r.getClass();
try {
valueField = c.getField("value");
valueField.set(r, newValue);
} catch (Exception e) { System.out.println(e); }
Message was edited by:
dfasdfsdafsadfasdf -
How to implement button installer using JNI or any native code
Hello All,
I am trying to implement installer that install button on internet explorer using JNI or native code so i am new to this technology .please suggest some approach.
Thanks AllWhy would you ever do that?
There are a host of languages that will do that and many scripting. You can easily write Applets and services in Java that will work in IE, but to just add a button... just doesn't make sense. -
Error code 404 keeps coming up on screen when I try to access Vodafone website (using Mac Pro)
Any ideas why only started happening in last week ?404 means the page you are looking for doesn't exist, if you are using a bookmark
type the website directly into your browser.
otherwise:
open terminal> type:
traceroute www.vodafone.com.au
you should get something like this: -
Class Libraries and Code used to Access Google Distance Matrix API
Hey Everyone....! I want to use Google Distance Matrix API with my C# application, which gets two co-ordinates(Latitude/Longitude) and pass them to API. Also to receive the results from API and construct and output class to interpret JSON objects.
Can anyone please tell me about class libraries and code used for above purpose.
LongbowHello,
If you want to use the Google Distance Matrix API, i suggest that you could post code sample demo to this api forum:
https://developers.google.com/maps/support/
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
JVM Crash When Using JNI and COM
I'm trying to call a DLL compiled from VB6 source code that I do not have access to. The VB6 code simply retrieves data from a DB2 database using ADO and my client code grabs that data and marshals it to my Java code. I'm attempting to achieve this using JNI and COM (without a third-party bridge). It works 75% of the time, but the other 25% of the time, the JVM crashes with the usual Hotspot crash log containing an access violation exception. However, I don't know what in my C++ code (VC++ 8) could be causing this except for passing a "wild" pointer to the code lying underneath the COM object interface. If that is the case, I don't know how I am doing that.
The Java code that is calling my native method is running on Tomcat 5.5.25 and just to be safe, I am not allowing multiple threads to concurrently call the method in my JNI DLL (though I realize that this will kill performance). Once I can get past this problem, I'll do the COM interfacing on a worker thread in my native code so I don't screw up CoInitialize and CoUninitialize calls in the case the same thread is concurrently executing multiple calls to my native code.
I've noticed that in most cases, the JVM crashes during my call to the pClsAccount->OpenConnection method. However, my DLL isn't what is listed on the top of the call stack, which is why I suspect the passing of a wild pointer, though I'm just taking a guess at that. Does anyone have an idea as to what's going on ?
JNIEXPORT jobject JNICALL Java_CustomerInfo_nGetCustomerAccountInfo(JNIEnv *env, jobject customerInfo, jstring accountNumber, jstring iniFileName)
jboolean isCopy;
// Account info class and instance to be instantiated
jclass accountInfoCls = NULL;
jobject accountInfoObj = NULL;
// The constructor ID of the accountInfoCls
jmethodID ctorID = NULL;
// Pointer to the interface for the ClsAccount COM object
_clsAccount *pClsAccount = NULL;
HRESULT hr;
BSTR bstrIniFileName(L"");
try
const char *nativeAccountNumber = NULL;
if (accountNumber != NULL)
nativeAccountNumber = env->GetStringUTFChars(accountNumber, &isCopy);
else
jclass newExcCls;
env->ExceptionDescribe();
env->ExceptionClear();
newExcCls = env->FindClass("java/lang/IllegalArgumentException");
env->ThrowNew(newExcCls, "accountNumber passed in was null !");
return NULL;
// Initialization
variantt varConnectionSucceeded = variantt(false);
variantt varGetAccountInfoSucceeded = variantt(false);
variantt varAccountNumber = variantt(nativeAccountNumber);
bstrt bstrLastPaymentDate = bstrt();
bstrt bstrLastErrorMessage = bstrt();
bstrt bstrLastErrorNumber = bstrt();
jlong jTotalDue = NULL;
jlong jEstablishedDueDay = NULL;
jlong jLastPaymentAmount = NULL;
jstring jLastPaymentDate = NULL;
jstring jLastErrorMessage = NULL;
jstring jLastErrorNumber = NULL;
jthrowable jException = NULL;
const char *chLastPaymentDate = NULL;
const char *chLastErrorMessage = NULL;
const char *chLastErrorNumber = NULL;
long long totalDue;
long long lastPaymentAmount;
long establishedDueDateDay;
//Convert string from Java string to C string to VB string
const char *nativeIniFileName = NULL;
if (iniFileName != NULL)
nativeIniFileName = env->GetStringUTFChars(iniFileName, &isCopy);
else
jclass newExcCls;
env->ExceptionDescribe();
env->ExceptionClear();
newExcCls = env->FindClass("java/lang/IllegalArgumentException");
env->ThrowNew(newExcCls, "iniFileName passed in was null");
return NULL;
bstrIniFileName = comutil::ConvertStringToBSTR(nativeIniFileName);
CoInitialize(NULL);
// Create an instance of the COClass with the interface over it
hr = CoCreateInstance(__uuidof(clsAccount), NULL, CLSCTX_INPROC_SERVER, __uuidof(_clsAccount), (void **)&pClsAccount);
if (hr == S_OK)
varConnectionSucceeded.boolVal = pClsAccount->OpenConnection(&bstrIniFileName);
 
if (varConnectionSucceeded.boolVal == -1)
varGetAccountInfoSucceeded.boolVal = pClsAccount->GetAccountPaymentInformation(&(varAccountNumber.GetVARIANT()));
env->ReleaseStringUTFChars(accountNumber, nativeAccountNumber);
// Extract all available account information from the ClsAccount object
if (varGetAccountInfoSucceeded.boolVal == -1)
totalDue = pClsAccount->TotalDue.int64;
establishedDueDateDay = pClsAccount->EstablishedDueDateDay;
lastPaymentAmount = pClsAccount->LastPaymentAmount.int64;
bstrLastPaymentDate = pClsAccount->LastPaymentDate;
chLastPaymentDate = comutil::ConvertBSTRToString(bstrLastPaymentDate.GetBSTR());
jTotalDue = (jlong)totalDue;
jEstablishedDueDay = (jlong)establishedDueDateDay;
jLastPaymentAmount = (jlong)lastPaymentAmount;
jLastPaymentDate = env->NewStringUTF(chLastPaymentDate);
delete[] chLastPaymentDate;
pClsAccount->CloseConnection();
// Populate error fields if any errors occur
bstrLastErrorMessage = pClsAccount->LastErrMessage;
chLastErrorMessage = comutil::ConvertBSTRToString(bstrLastErrorMessage.GetBSTR());
bstrLastErrorNumber = pClsAccount->LastErrNumber;
chLastErrorNumber = comutil::ConvertBSTRToString(bstrLastErrorNumber.GetBSTR());
jLastErrorMessage = env->NewStringUTF(chLastErrorMessage);
jLastErrorNumber = env->NewStringUTF(chLastErrorNumber);
delete[] chLastErrorMessage;
delete[] chLastErrorNumber;
const char* clsName = "com/nuance/merchantsmutual/businessentities/CustomerAccountInfo";
// Find the Java class and the ID of its constructor
accountInfoCls = env->FindClass(clsName);
ctorID = env->GetMethodID(accountInfoCls, "<init>", "(JJJLjava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
jException = env->ExceptionOccurred();
if (jException != NULL)
env->ExceptionDescribe();
env->ExceptionClear();
//Release all resources associated with the ClsAccount instance
pClsAccount->Release();
//Instantiate the class with the given parameters
accountInfoObj = env->NewObject(accountInfoCls, ctorID, jTotalDue, jEstablishedDueDay, jLastPaymentAmount, jLastPaymentDate, jLastErrorMessage, jLastErrorNumber);
jException = env->ExceptionOccurred();
if (jException != NULL)
env->ExceptionDescribe();
env->ExceptionClear();
else if (hr == REGDB_E_CLASSNOTREG)
cout << "COM class not registered" << endl;
else if ( hr == CLASS_E_NOAGGREGATION)
cout << "COM class can't be aggregated" << endl;
else if (hr == E_NOINTERFACE)
cout << "No interface for COM class clsAccount" << endl;
else if (hr == E_POINTER)
cout << "*ppv pointer was NULL !" << endl;
else
cout << "Error occurred while creating COM object. HR is [" << hr << "]" << endl;
// Free the BSTR because a new one was returned with a call to comutil::ConvertStringToBSTR
SysFreeString(bstrIniFileName);
// Release the string when it's no longer needed. MUST call if string won't be used
// anymore or else a memory leak will occur
env->ReleaseStringUTFChars(iniFileName, nativeIniFileName);
CoUninitialize();
 
catch (_com_error &e)
cout << "Encountered an exception in GetCustomerAccountInfo: Error was " << e.ErrorMessage();
pClsAccount->Release();
catch (...)
pClsAccount->Release();
return accountInfoObj;
Edited by: Cthulhu76 on Jan 5, 2010 9:18 AM0x49202400 JavaThread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" daemon [_thread_blocked, id=5340, stack(0x49bf0000,0x49c40000)]
0x48a7e800 JavaThread "Thread-1" [_thread_in_native, id=5976, stack(0x48f00000,0x48f50000)]
0x48a0dc00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=3072, stack(0x48c60000,0x48cb0000)]
0x48a09000 JavaThread "CompilerThread0" daemon [_thread_blocked, id=4988, stack(0x48c10000,0x48c60000)]
0x48a07c00 JavaThread "Attach Listener" daemon [_thread_blocked, id=3124, stack(0x48bc0000,0x48c10000)]
0x48a07000 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2572, stack(0x48b70000,0x48bc0000)]
0x489f5c00 JavaThread "Finalizer" daemon [_thread_blocked, id=5752, stack(0x48b20000,0x48b70000)]
0x489f4c00 JavaThread "Reference Handler" daemon [_thread_blocked, id=2596, stack(0x48ad0000,0x48b20000)]
0x003c6000 JavaThread "main" [_thread_in_native, id=4252, stack(0x00820000,0x00870000)]
Other Threads:
0x489f0400 VMThread [stack: 0x48a80000,0x48ad0000] [id=5624]
0x48a18800 WatcherThread [stack: 0x48cb0000,0x48d00000] [id=1192]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 36288K, used 12762K [0x02940000, 0x050a0000, 0x07800000)
eden space 32256K, 34% used [0x02940000, 0x0343af58, 0x048c0000)
from space 4032K, 37% used [0x04cb0000, 0x04e2ba28, 0x050a0000)
to space 4032K, 0% used [0x048c0000, 0x048c0000, 0x04cb0000)
tenured generation total 483968K, used 7518K [0x07800000, 0x250a0000, 0x42940000)
the space 483968K, 1% used [0x07800000, 0x07f57958, 0x07f57a00, 0x250a0000)
compacting perm gen total 14080K, used 14016K [0x42940000, 0x43700000, 0x46940000)
the space 14080K, 99% used [0x42940000, 0x436f0320, 0x436f0400, 0x43700000)
No shared spaces configured.
Dynamic libraries:
0x00400000 - 0x0040f000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\bin\tomcat5.exe
0x7c800000 - 0x7c8c0000 C:\WINDOWS\system32\ntdll.dll
0x77e40000 - 0x77f42000 C:\WINDOWS\system32\kernel32.dll
0x77380000 - 0x77411000 C:\WINDOWS\system32\USER32.dll
0x77c00000 - 0x77c48000 C:\WINDOWS\system32\GDI32.dll
0x77f50000 - 0x77feb000 C:\WINDOWS\system32\ADVAPI32.dll
0x77c50000 - 0x77cef000 C:\WINDOWS\system32\RPCRT4.dll
0x76f50000 - 0x76f63000 C:\WINDOWS\system32\Secur32.dll
0x77ba0000 - 0x77bfa000 C:\WINDOWS\system32\MSVCRT.dll
0x7c8d0000 - 0x7d0cf000 C:\WINDOWS\system32\SHELL32.dll
0x77da0000 - 0x77df2000 C:\WINDOWS\system32\SHLWAPI.dll
0x76290000 - 0x762ad000 C:\WINDOWS\system32\IMM32.DLL
0x77420000 - 0x77523000 C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.3790.3959_x-ww_D8713E55\comctl32.dll
0x6d7c0000 - 0x6da10000 C:\Program Files\Java\jre1.6.0_07\bin\client\jvm.dll
0x76aa0000 - 0x76acd000 C:\WINDOWS\system32\WINMM.dll
0x7c340000 - 0x7c396000 C:\WINDOWS\system32\MSVCR71.dll
0x6d270000 - 0x6d278000 C:\Program Files\Java\jre1.6.0_07\bin\hpi.dll
0x76b70000 - 0x76b7b000 C:\WINDOWS\system32\PSAPI.DLL
0x6d770000 - 0x6d77c000 C:\Program Files\Java\jre1.6.0_07\bin\verify.dll
0x6d310000 - 0x6d32f000 C:\Program Files\Java\jre1.6.0_07\bin\java.dll
0x6d7b0000 - 0x6d7bf000 C:\Program Files\Java\jre1.6.0_07\bin\zip.dll
0x6d570000 - 0x6d583000 C:\Program Files\Java\jre1.6.0_07\bin\net.dll
0x71c00000 - 0x71c17000 C:\WINDOWS\system32\WS2_32.dll
0x71bf0000 - 0x71bf8000 C:\WINDOWS\system32\WS2HELP.dll
0x71b20000 - 0x71b61000 C:\WINDOWS\system32\mswsock.dll
0x5f270000 - 0x5f2ca000 C:\WINDOWS\system32\hnetcfg.dll
0x71ae0000 - 0x71ae8000 C:\WINDOWS\System32\wshtcpip.dll
0x76ed0000 - 0x76efa000 C:\WINDOWS\system32\DNSAPI.dll
0x76f70000 - 0x76f77000 C:\WINDOWS\System32\winrnr.dll
0x76f10000 - 0x76f3e000 C:\WINDOWS\system32\WLDAP32.dll
0x76f80000 - 0x76f85000 C:\WINDOWS\system32\rasadhlp.dll
0x4a6a0000 - 0x4a6ac000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\CustomerInfoProxy.dll
0x77670000 - 0x777a9000 C:\WINDOWS\system32\ole32.dll
0x77d00000 - 0x77d8b000 C:\WINDOWS\system32\OLEAUT32.dll
0x7c420000 - 0x7c4a7000 C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_E6967989\MSVCP80.dll
0x78130000 - 0x781cb000 C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_E6967989\MSVCR80.dll
0x777b0000 - 0x77833000 C:\WINDOWS\system32\CLBCatQ.DLL
0x77010000 - 0x770d6000 C:\WINDOWS\system32\COMRes.dll
0x77b90000 - 0x77b98000 C:\WINDOWS\system32\VERSION.dll
0x75da0000 - 0x75e5d000 C:\WINDOWS\system32\SXS.DLL
0x75e60000 - 0x75e87000 C:\WINDOWS\system32\apphelp.dll
0x4dc30000 - 0x4dc5e000 C:\WINDOWS\system32\msctfime.ime
0x4b0d0000 - 0x4b395000 C:\WINDOWS\system32\xpsp2res.dll
0x71bb0000 - 0x71bb9000 C:\WINDOWS\system32\WSOCK32.dll
0x4bbe0000 - 0x4bbea000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\ClearTranProxy.dll
0x745e0000 - 0x7489e000 C:\WINDOWS\system32\msi.dll
0x71c40000 - 0x71c97000 C:\WINDOWS\system32\NETAPI32.dll
0x4bc50000 - 0x4bc6c000 C:\WINDOWS\system32\DBNETLIB.DLL
0x71f60000 - 0x71f64000 C:\WINDOWS\system32\security.dll
0x76c90000 - 0x76cb7000 C:\WINDOWS\system32\msv1_0.dll
0x76cf0000 - 0x76d0a000 C:\WINDOWS\system32\iphlpapi.dll
0x761b0000 - 0x76243000 C:\WINDOWS\system32\crypt32.dll
0x76190000 - 0x761a2000 C:\WINDOWS\system32\MSASN1.dll
0x4bcf0000 - 0x4bcff000 C:\Program Files\Common Files\System\Ole DB\SQLOLEDB.RLL
0x4a8a0000 - 0x4a8aa000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\MIGI.DLL
0x73570000 - 0x736c2000 C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib\MSVBVM60.DLL
0x4a950000 - 0x4a9e2000 C:\Program Files\Common Files\System\ado\msado15.dll
0x74a50000 - 0x74a6a000 C:\WINDOWS\system32\MSDART.DLL
0x4c850000 - 0x4c8c9000 C:\Program Files\Common Files\System\Ole DB\oledb32.dll
0x4dbb0000 - 0x4dbc1000 C:\Program Files\Common Files\System\Ole DB\OLEDB32R.DLL
VM Arguments:
jvm_args: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 5.5 -Dcatalina.base=C:\Program Files\Apache Software Foundation\Tomcat 5.5 -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\endorsed -Djava.io.tmpdir=C:\Program Files\Apache Software Foundation\Tomcat 5.5\temp -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=C:\Program Files\Apache Software Foundation\Tomcat 5.5\conf\logging.properties -Djava.library.path=C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\MMI\WEB-INF\lib vfprintf -Xms512m -Xmx1024m
java_command: <unknown>
Launcher Type: generic
Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_07
[error occurred during error reporting (printing environment variables), id 0xc0000005]
--------------- S Y S T E M ---------------
OS: Windows Server 2003 family Build 3790 Service Pack 2
CPU:total 4 (4 cores per cpu, 1 threads per core) family 6 model 7 stepping 6, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3
Memory: 4k page, physical 2097151k(2097151k free), swap 4194303k(4194303k free)
vm_info: Java HotSpot(TM) Client VM (10.0-b23) for windows-x86 JRE (1.6.0_07-b06), built on Jun 10 2008 01:14:11 by "java_re" with MS VC++ 7.1
time: Mon Dec 28 15:24:00 2009
elapsed time: 600 seconds -
Hi,
This is the first time I use jni and I encountered some problem when trying to accessing instance fields. My source code is as follows:
java side:
class C {
int j;
private native void f();
static { System.loadLibrary("C"); }
public static void main(String[] args)
C c = new C();
c.j = 5;
System.out.println("Before calling: " + c.j);
c.f();
System.out.println("After calling: " + c.j);
native (c) side:
#include <stdio.h>
#include "C.h"
JNIEXPORT void JNICALL Java_C_f(JNIEnv *env, jobject obj)
jfieldID fid;
jclass cls = (*env)->GetObjectClass(env, obj);
fid = (*env)->GetFieldID(env, cls, "j", "I");
if (fid == 0) {
return;
printf("Before set: %d\n", (*env)->GetIntField(env, cls, fid));
(*env)->SetIntField(env, cls, fid, 100);
printf("After set: %d\n", (*env)->GetIntField(env, cls, fid));
The programs compile and run smoothly, but the result is not what I expect. Please see the result below:
jason1:~/jni/accessInstanceVar> make
javac C.java
javah -jni C
gcc \
-I/usr/lib/jdk1.1/include \
-I/usr/lib/jdk1.1/include/linux \
Java_C_f.c -c -o libC.o
gcc -shared -o libC.so libC.o
java C
Before calling: 5
Before set: 196653
After set: 100
After calling: 5
I don't know why the value of the instance variable is not 5 when first accessed in the native function and why it is still 5 after the native function returns.
Can someone help me? Thanks in advance!
YongIt looks to me like you try to set a value of an instance variable like a static varibale.
I think you need exatra information like the object which the instance variable like so:
(*env)->SetIntField(env, obj, fid, 100);;
instead of
(*env)->SetIntField(env, cls, fid, 100);
Hope this will help
Joeseph. -
To read a DLL from java using JNI
Hi,
I had some DLL files (VB 5.0) which are providing interfaces. Is there any chance of accessing that using java (JNI). Also is there any De - Compiler available so that I can get the source code of the DLL file.
Regards,
Hari.Hola Hari
To make a dll loadable through JNI, the interface
inside
the dll must be implemented the JNI way. Also a COM
interface does not help.
I would reccomend a certain product to automatise the
JNI interfacing process, but that would
require that you have the sourcecode of the dll
available.
But one thing you can do is to write a wrapper that
contains the dll classes and is implemented the JNI
way.
More precisely you write an interface wrapper in c/c++
that matches the methods of the dll and does use JNI
methods. Now inside that c++ wrapper you load the dll
and forward the calls from java to c++ vice versa.
Download the demo version of CENTRO.java here:
www.ablon.de
Bye, nilsHi Nils,
Thank you for your suggestion. Im new to JNI.
That dll's are in Visual Basic. I don't have the source code of the dll file. I got the interfaces available in the dll file from a Visual Basic program which make use of the dll file(which we are talking about). As I know only the method signatures in the interfaces(dll file), I request you to kindly provide me some help to wrap it in C/C++ program.
Thanks in advance.
Regards,
Hari.
Maybe you are looking for
-
WRT54G firmware failure leaving no access to router config
I have a WRT54G router. Running Vista SP2 64-bit on a laptop wired to router. When I first tried to upgrade the firmware I was connected wirelessly. (I know, please just think it but don't type it) During the upgrade the internet connection disco
-
Help required - running a Java program from the command line
Hi, I have a small non-graphical Java application, packaged into a Jar file. My program relies on classes in another (external) Jar file. When I run the application from the IDE, everything works fine. However, when I try to run the application from
-
Moving an image does not work correctly
I have Photoshop CS4, version 11.0.2, installed on a 64-bit Windows 7 system. I am attempting to complete an exercise which requires me to move one image on top of another. I do not recevie an error messge. The function simply fails. All software
-
Why can't I upgrade from CS 5.5 design premium to CS 6 design standard with purchased DVD and valid serial nos?
-
is there a way i can deleate the songs i downloaded onto my computer and keep them on my ipod with out it deleating all the songs on my ipod the next time i plug it into my computer