473,323 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

JNI : calling native code from java

hi i just wanted to parse a file to find certain associated data
for ex if my text file is :
<!#first>This is string1
<!second>THis is string2
So if user types in first...he will get This is string 1
iv written a simple C++ code to parse the text file
but now i need to call that native code from a java source
i tried to write the native function but dont have much idea abt JNI so could someone help me out pls...


jstring
Java_com_example_hellojni_HelloJni_stringFromJNI( JNIEnv* env,
jobject thiz,jstring javaString )
{



using namespace std;
const char *nativeString = env->GetStringUTFChars(javaString, 0);
string val1,val2;
string inp(nativeString);
cout<<"enter:";
cin>>inp;
string line;
ifstream myfile ("data.txt");
if(myfile.is_open())
{
while(!myfile.eof())
{
getline(myfile,line,'<');

istringstream iss1(line);
getline(iss1,val1,'>');
val1.erase(0,2);
getline(iss1,val2);

if(inp.compare(val1)==0)
cout<<"\n Our returned string is : "<<val2;
}
}
char buffer[20]
strcpy(buffer, val2.c_str());


return *env->NewStringUTF(env, buffer);

}
Jun 16 '10 #1
3 1661
myusernotyours
188 100+
This more has to do with Java than C/C++, better to ask this kind of question on the Java forum...

Also you could do this in pure Java. Is there any specific reason for using native code?

There is a wealth of information that you may want to look at here.

King Regards,

Alex.
Jun 17 '10 #2
hey thanks...
theres no real reason as such..
it can be done with pure java but i wanted to try getting the hang of using native code..so im just trying to learn it myself
thanks
Jun 18 '10 #3
myusernotyours
188 100+
Okay then, I imagined so too. Go ahead and check out that link.
Get back here if you get into any problems. Good Luck!

Alex.
Jun 18 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: commosoft | last post by:
Hi all, have you ever seen this kind of error? This happens only on certain types of Sun machines (SunFire280R) but not on other types of machines (SunBlade2000 or SunBlade100). I tried to...
1
by: Mats Olsson | last post by:
I have a native process (written in c) which generates an unknown number of bytes (jpeg images), and I would like to find an efficient way of transferring these bytes from native to java, the end...
2
by: Peter Schmitz | last post by:
Hi, I just created a solution that is based on unmanaged C++ code. Now, the .net framework consists of some cool functions and classes - there is especially one namespace I'd like to use....
2
by: Pawan Aggarwal | last post by:
I'm having trouble with calling an exported function in a native DLL compiled with eMbedded Visual C++ in C# application in PocketPC 2002 OS. Problem Description follows: I have one exported...
1
by: Bern McCarty | last post by:
What do you make of this? I cannot tell for sure but it almost seems as the the transition thunk to get back from the native bool method to the managed caller is looking at eax and, if any bit is...
1
by: tweety | last post by:
wat does "native code" in firefox dom inspector mean? function hasAttribute() { } can anyone help me with this? Thanks in advance,
2
by: Haroon_Saeed | last post by:
Hey, I wrote a managed c++ class library in viusal studio 2005. This managed c++ dll calls native C++ methods of an SDK. When I referenced this managed c++ library in a console applciation...
2
by: Dave Burns | last post by:
Hello, We have a situation where a managed C++ assembly links with native C++ dll. There is a callback mechanism which calls back into the managed code asynchronously. Since native classes...
2
by: =?Utf-8?B?QXJuZSBHYXJ2YW5kZXI=?= | last post by:
I call native code from my .net app <DllImport(SENDFORMPDFTest, EntryPoint:="FORMEXIST", _ SetLastError:=True, CharSet:=CharSet.Ansi, _ ExactSpelling:=True, _...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.