riahc3 50 Â Team Colleague

Well good luck.
Without a controlled/known output from the C++ program, it will be hard/impossible to write a java program to mimic the C++ program.
If you can have the C++ program write out a known sample of data to a file, we can write a java program to write the same bits to a file given the same sample of data.

I shouldnt have said anything about a C++ program.....

I simply want to write a array full of ints to a binary file. Nothing else. Forget about the C++ program.....

(Didnt work today as it is a holiday) I writed the writeInt method and lets see if the PLC reads it.

riahc3 50 Â Team Colleague

I don't know about JNA but there isn't a suma or sum method in Java. Usually you need to create a sum integer variable and calculate sum = a+b and print out the variable, System.out.println(sum). You also need to initiate and assign a and b values...

I made that function in C++ and read it from a library in C++ from Java. Its a personalized function :)

riahc3 50 Â Team Colleague

Computers are very fussy about the location and order of bits.
Are there any programmers where you are that we can talk to about your problem?

Besides ourselves :P no. Thats another problem; We cant see their C++ code (even if we dont understand C++) and start writing and when something comes up that we dont understand, ask. Its limited and antiproductive. Right now, besides this, we having to do and you know the saying: Time is money. We have noone to report to right now so, here we are stuck.

riahc3 50 Â Team Colleague

DataOutputStream and writeInt(...)

Will retry now DataOutputStream and writeint even though like someone mentioned it might be short because int in C++ has 2 bytes and in Java it is 4 bytes, correct?

We need to see how the C++ program writes a few known integer values to a file.
When we see the order of the bits in the file for the known integers, we can write the java code to write the bits for the same numbers to a file in the same order.
For example if C++ writes the int value 20 to a file and the bits in the file are 1400
for that number than we can write a Java program that will write the same bits for the number 20.
We must have samples for several numbers from small numbers to large numbers.

The C++ program writes more than just ints. We are writing a array of ints as a test to see if the PLC will read it. From then on forward, we can write more things. We are only going to write numbers, especifically from what I have been told ints and doubles (floats).

The order is already computed by the C++ program (which is being rewritten in Java by parts. The order of those parts I cannot determine as they give us chunks of code, not in any particalur design or order).

From what I gather, he simply writes the number as is, not …

riahc3 50 Â Team Colleague

BMP picture or machine instructions? Am I the only one who is confused?

Machine instructions. Like I said, dont quote me on that as I could not confirmed it until you said that it contained "11112222" and numbers like that.

Sorry about that confusion.

riahc3 50 Â Team Colleague

The problem is your original post said "How do I do this in Java giving the same output as the C++ program?".
Without that constraint, writing Java ints to a bin file is trivial.
This being a Java forum you can't assume that we know how C++ writes binary files.

My mistake :)

(For now), I just want to write from Java the int numbers in a array to a bin file. Thats it.

I apoligize for any misunderstanding.

riahc3 50 Â Team Colleague

So, your first 4 values are 11111111 11112111 11234111 22222222 ...
and the file begins (in hex bytes) 14,00,00,00,28,00,00,00,D8,8A,01,00 ...

Sorry, but I can't see any connection between those two. I have no idea how those integers are encoded into that hex.
Maybe we can go to something simpler, like writing the values 1,2,3 to a new file from the C++ program and dumping the resulting file?

Yes. Thank you :) Ill explain.

Those 8 digit numbers such as "11111111" and "11112111" are signals for a machine. Example:
11111111 might mean to stop the machine
11112111 might mean to start the machine
11231211 might mean to emit a sound

Thats why my array (like I mentioned) are:

array[1]=11113333;
array[2]=11114444;
array[3]=99999999;

and so forth. I just need to know how to do that in Java. Nothing more, nothing else. Write a array full of 8 digit numbers to a .bin file.

riahc3 50 Â Team Colleague

Now you need to show the values that were written to create the bin file.

This is the bin file used to generate what I believe is a BMP (Dont quote me on that) of a picture of 2 horizontal pieces and 2 vertical pieces of a rectangule (splitting it up into 4 pieces)

Like I mentioned I believe, the C++ program does calculation for this (and alot more things) but for now I simply want to make a bin file with a array full of int numbers.

riahc3 50 Â Team Colleague
riahc3 50 Â Team Colleague

Ill put it on imageshack. One second....

riahc3 50 Â Team Colleague

Yes. There is a attached PNG. You dont see it?

riahc3 50 Â Team Colleague

I suppose that the attached file is what you want

riahc3 50 Â Team Colleague

Please tell exactly what the correct contents of the file should be, in hex.

Ill try to get that to you ASAP. He didnt come to work today (I dont think he is coming any day today: There is a holiday tommorow, thursday and friday)

riahc3 50 Â Team Colleague

(enteros is array; Messed up when changing the name in the post sorry)

riahc3 50 Â Team Colleague

Tried with the writeShort method and still didnt work. (gave me a 4 byte file which didnt work)

He uses this to write:

std::ofstream myfile(str_file.c_str(), ios::out|ios::trunc|ios::binary);
str_file is the name of the file to store, for example C:\\x\\fileofbin.bin
myfile.write(reinterpret_cast<char*>(&x_1),sizeof x_1);

I am trying a array of integers from 0 to 14 (the positions) with just some ints such as

11111111;
11112111;
11234111;
22222222;
0;
-11111112;
69384959;
10;
1;
55555555;
10101010;
88888888;
-98765432;
-9;
1;

All these are stored in a array, I go thru the array with a for (in most logical cases) and write them to a binary file.

Things Ived tried:

(In this example I did this:

Object obj=new Object();
obj=array;

That explains that attempts with obj
)

/*1*/    //	data_out.writeByte(enteros[i]);
/*2*/    //	data_out.writeByte(Integer.parseInt((String)obj));

		    	
/*3*/    //	data_out.writeBytes(String.valueOf(array[i]));
/*4*/    //	data_out.writeBytes((String)obj);
		    	
/*5*/   //	data_out.writeObject(obj);
/*6*/   //	data_out.writeObject(array[i]);
		    	
		
/*7*/  //	data_out.writeObject(array); 
/*8*/ //data_out.writeShort(array[i]);
riahc3 50 Â Team Colleague

OK, sorry about the confusion. writeInt in a for loop sounds right. Can you post the exact code? Remember that Java ints are 4 bytes, not 2. For a 2-byte int you need a "short".
Maybe you can post the original int array values, and a hex dump of what you expected and what you actually got in the file. That would allow us to home in on the correct solution.

Wow that could be a big hint.
So in C++ ints are 2 bytes and in Java they are 4 bytes? Did not know this and it could be a important step.

How about double in Java? Any different byte sizes with double/float/etc in C++?

This is for where I work so Im going to have to get back to you on that on Monday.

riahc3 50 Â Team Colleague

Thank you for the replies

Starting with a Serializable object, you can write it to an ObjectOutputStream with a single write, and read it back from a corresponding ObjectInputStream ditto.

NB: The JavaDoc for many classes warns that the serialisation format may change from one release of Java to another, so its not suitable for writing files for long-term storage of data, but it's OK for short-term storage or sending Objects over TCP/IP sockets etc.
For a safer and more comprehensible approach, have a look at XMLEncoder and XMLDecoder. These utility classes convert Objects with standard getter/setter methods into a simple XML format that you can safely write/read/send just like any other pure text file.

The files are short-term storage (as a matter of fact, they are one time usage almost)

From the other post (later on, which I also quote), not sure if you understood me correctly.

Can you look at the file the C++ program generates with a hex editor?
If the contents of the file are the bytes for an int variable, a java program can write out the same bytes as a C++ program.

The C++ generates other data but mainly those integers which can be read by a PLC. Im not sure if seeing it with a hex editor will clear up things or not but ill try it out.

OK, looking at Norm's post I may have answered the wrong question.
Do you want to write objects …

riahc3 50 Â Team Colleague

Hey

I was wondering how I could write a binary file in Java with code in C++ using the reinterpret_cast function. If I remember the line correctly (not currently at work) it was:

file.write=reinterpret_cast<char *(&x)>,sizeof x;

with x being a variable.

How can I do that in Java? From reading around, many topics said I should make the class Serializable. Would it be something like this?

public class anumber implements Serializable 
{
       private int x; /*Not sure if that is the correct way as I am not doing it in a IDE to declare it but know what i mean*/
        
       public int getx()
        {
            return x;
        }

       public void setx(int y) //y being the variable i pass to this function
        {
           this.x=y;
         }

}

then in another class

public class whatever
{
    public void main()
    {
       anumber b=new anumber();
      /*NEEDS HELP FROM THIS POINT TO WRITE THE NUMBER/VARIABLE x TO A BINARY FILE*/
    }
}

Where I comment "/*NEEDS HELP FROM THIS POINT TO WRITE THE NUMBER/VARIABLE x TO A BINARY FILE*/" is obviously where I am stuck. Do I write the object b directly using the OutputStreamWriter (I belive it is) or do i use b.getx() and write that?

From what Ive been told the C++ code write bytes such as this:

10101010
11111111
92839423

from integers into the binary file.

How do I do this in Java giving the same output as the C++ program? Thank you

riahc3 50 Â Team Colleague

Im switching too much between these "wrapper" frameworks so I think I should just concentrate on one and leave the others alone. Which should I go for in a servlet like enviroment? JNI, JNA or Swig? The only one I have "expirence" with is JNI. The rest Im playing around without getting it to work (Got JNA to work with helloworld)

riahc3 50 Â Team Colleague

Honestly, this is too much work to try and help out with. I'd suggest hire someone.

I didnt expect that type of answer but oh well. Thanks for at least looking at it

riahc3 50 Â Team Colleague

Any help at all?

We may think that all the libraries are free, not sure. Here is a list of all the .js files:

[IMG]http://img208.imageshack.us/img208/7100/filesh.jpg[/IMG]

Thank you

riahc3 50 Â Team Colleague

As some of you have read, Ive been working with JNI for these days. Ive found that JNA may be easier to manage and also allows some other things.

I have this very simple program:

The .cpp:

#include <stdio.h>
#include "PruebasDeJNA.h"

int suma(int a,int b)
{
	return a+b;
}

The .h:

#include <stdio.h>

int suma(int,int);

All it does is add two numbers and return them. Nothing more.

In my .java program:

package hola;

import com.sun.jna.*;

public class Mundo 
{
	public interface PruebasDeJNA extends Library 
	{ 
		PruebasDeJNA INSTANCE = (PruebasDeJNA)Native.loadLibrary((Platform.isWindows() ? "PruebasDeJNA" : "c"),PruebasDeJNA.class);
		int suma(int a,int b); 

	}

	public static void main(String[] args) 
	{		
			System.out.println(PruebasDeJNA.INSTANCE.suma(5, 7));
         }
}

The error that it gives me is that it cannot find the function "suma" in the library.

As you can see, avoiding porting the code from C++ to Java is neccesary as there are too many lines to port over and the program is alot of math so one miscalulation could throw away alot of work.


Thanks for the help

riahc3 50 Â Team Colleague

a) Not everything in Java starts with a "J".

b) if (x.equals("*"))...

This code is in C++, not Java. I believe variable dot something doesnt exist in C++ (AFAIK).

jstring is the same as const char * as stated in jni.h

riahc3 50 Â Team Colleague

(More JNI woes...)

When I try to comply this code

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HacerOperacionesConJNI
 */
public class HacerOperacionesConJNI extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
	private native double operaciones(double a,double b,String op);
       
    public HacerOperacionesConJNI() 
    {
        super(); 
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String num1=request.getParameter("num1");
		String num2=request.getParameter("num2");
		String op=request.getParameter("op");
		double res;
		res=operaciones(Integer.parseInt(num1),Integer.parseInt(num2),op);
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>Resultado</TITLE></HEAD>");
		out.println("  <BODY>");
		out.println("El resultado entre " +num1+" y "+num2+" utilizando el operador " + op + " es " + res);
		out.println("  </BODY>");
		out.println("  </HTML>");
		
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		String num1=request.getParameter("num1");
		String num2=request.getParameter("num2");
		String op=request.getParameter("op");
		double res;
		res=operaciones(Integer.parseInt(num1),Integer.parseInt(num2),op);
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>Resultado</TITLE></HEAD>");
		out.println("  <BODY>");
		out.println("El resultado entre " +num1+" y "+num2+" utilizando el operador " + op + " es " + res);
		out.println("  </BODY>");
		out.println("  </HTML>");
	}
	static
	{
		System.loadLibrary("HacerOperacionesConJNI");
	}

}

to produce a .class file, this error pops up:

HacerOperacionesConJNI.java:6: package javax.servlet does not exist
import javax.servlet.ServletException;
^
HacerOperacionesConJNI.java:7: package javax.servlet.http does not exist
import javax.servlet.http.HttpServlet;
^
HacerOperacionesConJNI.java:8: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
^
HacerOperacionesConJNI.java:9: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
^
HacerOperacionesConJNI.java:14: cannot find symbol
symbol: class HttpServlet
public class HacerOperacionesConJNI extends HttpServlet
^
HacerOperacionesConJNI.java:25: cannot find symbol
symbol : class HttpServletRequest

riahc3 50 Â Team Colleague

(So continues the JNI saga....)

I currently have this (in C++, this being my native code in C++):

(x is a jstring passed thru the header)

jdouble res;
	if (x=="*")
	{
		res=a*b;
	}
	else if (x=="+")
	{
		res=a+b;
	}
	else if (x=="-")
	{
		res=a-b;
	}
	else if (x=="/")
	{
		res=a/b;
	}
	else
	{
		res=-9999;
	}
	 return res;

but it says that jstring (x) and const char * (the things after the "==" for example the "*") are not compatible: "Error: operand types are incompatible ("jstring" and "const char *")"

riahc3 50 Â Team Colleague

It know it is difficult without any code but I hope you understand :)

riahc3 50 Â Team Colleague

Good luck with your project. :-)

Thank you it tooks us 5 pages of daniweb, 4 days, your help, and headaches to get hello world working. I have no idea how were are going to get his program working with .cpp and .h files that call each other and functions and etc etc....

riahc3 50 Â Team Colleague

Without being able to see the code it will be hard to help. My only suggestion is to store the points you want to remember into hidden text boxes. This way when you submit, those values will be submitted as well.

Thanks for the help :)

The drawing type program is already made and the points are stored somewhere so there isnt any hidden text boxes.

Ill post screenshots which I think I wont have problems.

[IMG]http://img5.imageshack.us/img5/204/drawj.jpg[/IMG]

[IMG]http://img804.imageshack.us/img804/3709/debugn.jpg[/IMG]

The first image is the original drawing but in the actual program. The colors are irrelevent but the type, spline or line, is. And so is the order which is the same as the mockup original drawing.

The second image is a debug window he included so we can see the process when I click on the canvas (thats: "[info] - PointManager.js - addPoint 1 X: 143 Y:206 Tipo: spline" which stores the first click I made with the type. The next are the same but saying addPoint 2, addPoint 3, etc etc), make the lines (no debug output), change line type (that is "[info] - PointManager.js - Cambiamos a tipo: line" and "[info] - Polyline.js - Despues el dinamico es: line") , and end the drawing (that is "[info] PolylineDraw.js - Terminamos de dibujar").

Like I said, I cant post any code just in case.

All I do with changes on …

riahc3 50 Â Team Colleague

> C:\HelloWorld.dll: Can't find dependent libraries

When you load a DLL, the dependent DLL's get loaded as well and if they are not found, this error is raised. The dependent DLL's should be in the PATH env variable or in -Djava.library.path system property. Assuming you are not using -Djava.library.path, do both of you have the same PATH env settings? Do you see any difference in there?

Also, do you have a conflicting version of DLL's in the directories on your PATH (i.e. you have a.dll ver 1 and your partner has got a.dll of ver 2 in system32 folder).

We have modified our PATH to be the same and it works now on his PC. Thank you very much. You have helped us out alot and without a doubt without you we could not have resolved this.

Thanks alot.

riahc3 50 Â Team Colleague

Hey

Ive been given a JavaScript program (with embedded in a HTML) with several (from what Ive seen) free libraries. For example:

excanvas.js
jquery-1.6.4.min.js
prototype.js
colorpicker.js

This JavaScript program (using those and other free libraries) to draw something like this:
[img]http://img339.imageshack.us/img339/3997/dibujoajyu.jpg[/img]

As you see the dots, beside having a X and Y, have a certain order and also the last point closes with the first point.

Looking thru the code (with no comments) I cant find exactly where the points are stored so I can retreive them when I press a submit button and send them to a DB. What should I look for (besides X and Y)? What I mean is what the programmer problably did: Store in a array, make a class for each point, etc.

I cannot post the code as it is my company's and the other's so I dont know what legal inplications it may have.

Thank you very much

riahc3 50 Â Team Colleague

The error is:

C:\>java HelloWorld
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\HelloWorld.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at HelloWorld.<clinit>(HelloWorld.java:10)
Could not find the main class: HelloWorld. Program will exit.


Both the .class and the .dll that works on my PC were there.

riahc3 50 Â Team Colleague

> Why doesnt it work on another PC?

More details as always. When you say "couldn't find library path", was is some linker exception? Which DLL/library did it say was missing? The one you created or a completely different one? Do both the computers have the same OS? You might also want to look at the other PC for old DLL's and do some cleanup if required.

BTW, it is not a requirement for the other PC to have Visual Studio installed on target machines, just the proper runtime would do.

I believe it came up with a LD_LIBRARY_PATH type of error. It didnt really state anything else but just in case my partner on this project will check it out now. Both are running XP and we have stated that we are going to format both PCs as there is "DLL hell" all over the place, with copies of DLLs in different folders.

Again, I cant thank you enough for your time. You have made it easier for both of us.

riahc3 50 Â Team Colleague

Im sorry to have not replied. I FINALLY was able to reproduce the .DLL and execute the java program using the C .DLL. I was even able to call a java program passing arguments (a simple add program) and it was able to give me a output.

The only problem I had is that I passed the HelloWorld.class and the HelloWorld.dll to another PC and he put it in the a folder both files. And it was not able to run. It said it couldnt find the the library path. On that PC, both VS and JDK was installed.

Some progress was done but obviously it needs to be ran on another PC to be able to work 100%.

I used the VS method you stated. That produced the .DLL (that and using the sun tutorial)

So thanks alot but that would be the only thing: Why doesnt it work on another PC?

riahc3 50 Â Team Colleague

> Fatal Error C1902: The program's data base administrator isnt the same; Please check the instalation.

What does a web search for the error code say? There are a lot of posts out there with th same question and solution; one of them might work out for you.

> What does SQL server have anything to do with this? It installs the express edition but why?

Not sure; during the installation, I unchecked everything.

I actually had a tab open searching for the error. Just wanted to keep a log of everything on this thread.

It was a old DLL so I uninstalled and reinstalled VS

On the reinstallation I only checked VS so Im going to try again....

riahc3 50 Â Team Colleague

Tried doing it in VS and it gives me this error:

Fatal Error C1902: The program's data base administrator isnt the same; Please check the instalation.

What does SQL server have anything to do with this? It installs the express edition but why?

riahc3 50 Â Team Colleague

> This might be a dumb question but would this make a normal C/C++ DLL or a C/C++ .NET DLL?

You would need a normal C/C++ DLL.

> And the C++ team pretty much have no clue how to make a .DLL

That's news. I hope you are not stuck with fresh-out-of-college-self-proclaimed C++ programmers...

Thats why I asked if VS would output a standard DLL using standard C++ libraries or would it output a DLL using .NET Framework.

And the C++ programmers have pretty much made the GUI, math calculations (alot more complex than 2+2), and made some binary files so a machine they have can read it and cut the metal sheet so I think they have a idea. They have just never needed to make a .DLL

riahc3 50 Â Team Colleague

> Could you be more especific when you say "setup the same thing in Visual studio"?

Simply set up a new DLL C project in Visual studio. Create new blank project. Right click project -> General -> Configuration Type set to Dynamic Library DLL

Right click Header folder -> add item -> add your header

Right click Source folder -> add item -> add your .c file

Right click project -> c/c++ -> Additional include directories -> add paths to java\include and java\include\win32

Right click project -> rebuild -> the output window will show you the location of the newly created dll

For more detailed instructions, you should probably speak with the C++ guys from your team since they should definitely be able to help you out with this one.

Ah ok :) I imagined you ment this but I just wanted to make sure.

This might be a dumb question but would this make a normal C/C++ DLL or a C/C++ .NET DLL?

And the C++ team pretty much have no clue how to make a .DLL They commented that once we get JNI working with some basic examples showing that it works, they will read up on DLLs and start on that part.

Tommorow Im going to try this out as well and Ill post back with the results (in about 7 and a half hours)

Thanks alot for all this troubleshooting :) Like I said, we are very thankful :)

riahc3 50 Â Team Colleague

This is definitely something specific to your machine and related to spaces in path or newlines. But don't think I would be able to pin-point the solution sitting here.

Let's try another approach; can you setup the same thing in Visual studio?

Could you be more especific when you say "setup the same thing in Visual studio"?

Currently Im not at work anymore (its currently 15:31) and I enter tommorow at 09:00, so Ill read and do it tommorow :)

riahc3 50 Â Team Colleague

What does this exactly mean in English?

LINK : fatal error LNK1181: no se puede abrir el archivo de entrada 'local\Temp\
_CL_1d74d141lk.obj'

Sorry thought you just didnt know the error code.

no se puede abrir el archivo de entrada 'local\Temp\
_CL_1d74d141lk.obj'

The file 'local\Temp\_CL_1d74d141lk.obj' cannot be opened.

riahc3 50 Â Team Colleague

Sorry....

cl.exe -I "c:\java\include" -I "c:\java\include\win32" -MD -LD mypkg_HelloWorld.c -Femypkg_HelloWorld.dll
riahc3 50 Â Team Colleague

What is the location of the directory from which you are invoking "cl.exe"? Also, can you try putting the -I paths in quotes? If that doesn't work, can you try:

I am invoking it from "C:\tutorial" where I have mypkg_HelloWorld.c and mypkg_HelloWorld.h

I tried what you put:

cl.exe -I "c:\java\include" -I "c:\java\include\win32" -MD -LD mypkg_HelloWorld.c -Femypkg_HelloWorld.dllcl.exe -I "c:\java\include" -I "c:\java\include\win32" -MD -LD mypkg_HelloWorld.c -Femypkg_HelloWorld.dll

and still nothing. Same error.

riahc3 50 Â Team Colleague

Visual Studio 2010 C++ Express.

riahc3 50 Â Team Colleague

Sorry, can't help you out on that one; not even sure what that error message means... If you have made any PATH related temporary changes for making this run (e.g. copying DLLs to the current directory etc.), now would be the time to undo those. Do you have multiple VS installations?

Also, paste the command line you are using here.

My PATH currently contains:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Archivos de programa\ATI Technologies\Fire GL 3D Studio Max;C:\java\bin

Nothing strange.

My command line is:

cl -Ic:\java\include -Ic:\java\include\win32 -MD -LD mypkg_HelloWorld.c -Femypkg_HelloWorld.dll


when I am located in the folder containing both the mypkg_HelloWorld.c and mypkg_HelloWorld.h

The c:\java\include and Ic:\java\include\win32 exist. Im using Visual Studio 2010 and none other.

riahc3 50 Â Team Colleague

What do you mean by "restart cmd"? After executing the bat file, you are supposed to use the same session for running cl.exe (assuming you have already added that particular folder to PATH) because changes made by the .bat file execution are transient and carry on only for that given session.

Did not know they only were for that session....

Did it and in the same session ran again the cl line in the tutorial and got this:

Compilador de optimización de C/C++ de 32 bits de Microsoft (R) versión 16.00.30
319.01 para 80x86
(C) Microsoft Corporation. Reservados todos los derechos.

mypkg_HelloWorld.c
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation. All rights reserved.

LINK : fatal error LNK1181: no se puede abrir el archivo de entrada 'local\Temp\
_CL_1d74d141lk.obj'

riahc3 50 Â Team Colleague

OK, you have to make sure that:
javah is in your path (at least temporary; so that you can directly invoke it without being in java\bin)

It was in path so it worked out of the box

You need to be in a directory just outside the "mypkg" directory which contains your HelloWorld.class file before invoking javah. To do this, search for where the HelloWorld.class is generated (should be autogenerated if build-automatically is on in Eclipse)
Open up "CMD" and CD to a directory just one level above the mypkg directory which contains HelloWorld.class.
Assuming your class is generated in the following directory strucure "c:\testproject\target\classes\mypkg\HelloWorld.class"; CD to the directory "c:\testproject\target\classes" and then invoke the javah command as "javah -jni mypkg.HelloWorld".

Did it and yes it generated my .h file.

If it works, continue with the step 3 in my previous post.

Continuing from step 3....

I arrive at step 5 to run vcvars32.bat,restart cmd and it still doesnt find cl.exe I manually add it to path....

And now I think ive discovered the problem: vcvars32.bat isnt working. Because after adding "C:\Archivos de programa\Microsoft Visual Studio 10.0\VC" where cl.exe is located, it says stdio.h is missing. (which it isnt)

riahc3 50 Â Team Colleague

Well, surprise surprise, I was able to do it with the command line compiler as well so I guess I'll just show you the steps in brief.

Thank you very much for the tutorial by you :) Im going to comment on each of your steps...

Create an eclipse Java project and inside that create a class which has the same contents as that of the tutorial. Just make sure it is in some package like "mypkg" etc.

Done. No problems at all

Generate the JNI header file using the "javah" utility as mentioned in the tutorial

Here starts some errors (which have never happened before at this stage). I cleared my PATH for your tutoral so the javah command doesnt work. Im going to add Java´s bin path which should include the javah command. I have my JDK installed at C:\java so I added to PATH C:\java\bin.

After adding that folder I try to run the command and it gives the following error:

error: cannot access HelloWorld
class file for HelloWorld not found
javadoc: error - Class HelloWorld not found.
Error: No classes were specified on the command line. Try -help.

This is normal as in MyEclipse I did not comply/build/run the program. Im going to do that now (as stupid as this may seem, Im try to do everything you posted to make sure I dont do anything wrong so if you dont say comply, I wont)

Tried to …

riahc3 50 Â Team Colleague

I'm not sure what exactly are you doing there. After reaching home, it took me 30 mins to run the hello world example. Are you sure you are able to properly build the DLL file? The steps in the tutorial might be a bit problematic in case you are using Visual Studio. Did you make sure you add "jvm" headers and "jvm" libraries to the linker when building the project?

You might need to jot down here "what" steps you are taking when using Visual Studio Express Edition to build the DLL down to the minute details.

Well the tutorial does say to use cl.exe included in Visual Studio. I dont open Visual Studio at all. I simply use the cl.exe included in the instalation as it says in the tutorial.

As I said, Ill try once again tommorow to do the project again from scratch as see what happens. Ill jot everything down as well.

riahc3 50 Â Team Colleague

OK, you should never have to add any random DLL to your path so for the time being forget about manually adding DLL's. How are you building the wrapper project: using IDE or command line? Using Visual Studio? How is your library distributed, as a DLL or LIB?

This is how our project is structured wrt dependencies (Windows):

Additional libraries included on the path:
%JAVA_HOME%\lib\jvm.lib
path\to\your\graphics\library\something.lib
Additional header includes directory:
%JAVA_HOME%\include
%JAVA_HOME%\include\win32
path\your\graphics\project\header\files

We are currently trying to do the Hello World program found here: http://java.sun.com/docs/books/jni/html/start.html#769

Nothing more, nothing else.

(In the Hello World program example) we wanted out C++ library to be a .DLL . Since the commands are all done from the command line (in the example), we also ourselves do it from cmd. But like I said, everything comes to a stop at 2.6 with the explaination I gave above.

This is under Windows XP and I installed Visual Studio 2010 Express C++ Edition. As IDE in Java, Im using MyEclipse. The JDK is the latest of version 6, not 7.

riahc3 50 Â Team Colleague

I need more details; which part of step 2.6? The part where you try to load your wrapper DLL or the part where you try to create your wrapper DLL?

To create your own wrapper DLL, you'll need to specify the headers (.h files) and libraries (.lib files) for the JVM and your own C++ project.

The first error was that a .dll was missing. That file was "mspdb80.dll". As a fix, we simply added to PATH where it was located and then it gave us other error about stdio.h which we did the same thing or copied it to the same folder as our .C, .H, .class, .java files (we have deleted and redone the tutorial so many times that we have actually forgetten the steps) at last, after working PATH, copying files, including more folders in the -IC:\somefolder, until the linker started erroring out on _CL_randomstufflk.obj files and each time I ran the command it changed the randomstuff part so we are kind of stuff there.

Both of us appriciate very much the help as we are stuck here in a world of pain so to speak.

Thank you very much.

riahc3 50 Â Team Colleague

Ive followed this tutorial several times

http://java.sun.com/docs/books/jni/html/start.html#769

And at 2.6 it always gives a error about a .dll missing (and it is there) No matter what I modify in the PATH it always asks for another and another....

Is there any other recommended tutorial out there? Most usually copy that one and modify it some....