Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 09:23

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[REQUEST]Information about link between C++ trainer and java GUI?

Discussion on [REQUEST]Information about link between C++ trainer and java GUI? within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
strontklit's Avatar
 
elite*gold: 0
Join Date: Mar 2012
Posts: 220
Received Thanks: 117
[REQUEST]Information about link between C++ trainer and java GUI?

Hi,

My friend recently developed a C++ trainer for a game and i was planning on creating a nice GUI for it in java language, with dmg calculator and such in it, but also including the trainer...

Now i was hoping to get some tips on what is the best way to link these to together? How should i load the c++ trainer into the GUI?

I've heard i should use .dll files and load that but i am not really sure on how to do that. And ofcourse maybe there are some other ways of doing this?

I hope to get some nice responds containing useful information

Thanks in advance!
strontklit is offline  
Old 06/13/2012, 13:36   #2
 
elite*gold: 0
Join Date: Jun 2012
Posts: 1
Received Thanks: 1
Yes, you should use shared libraries and load them. (JNI)
It's pretty easy but the C++ trainer must be modified or must provide interfaces.
Here's an example using JNI:
Code:
// JNITest.java
public class JNITest {
  private native float add(float a, float b);

  static {
    System.loadLibrary("JNITestLib");
  }

  public static void main(String... args) {
    JNITest test = new JNITest();
    float erg = test.add(12.5f, 5.7f);
    System.out.println(erg);
  }
}
Methods you want to implement in C/C++ must be declared as native.
In static context you load the library. Make sure you only commit the file's name without extension. Java will do that automatically (on Windows systems .dll, on Linux .so).
Now, you can compile that file using java's compiler javac.
Code:
javac JNITest.java
If the JNITest.class file was created, you have to use the java tool "javah".
Code:
javah -jni JNITest
A C/C++ header file will be created with the following content:
Code:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNITest */

#ifndef _Included_JNITest
#define _Included_JNITest
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     JNITest
 * Method:    add
 * Signature: (FF)F
 */
JNIEXPORT jfloat JNICALL Java_JNITest_add
  (JNIEnv *, jobject, jfloat, jfloat);

#ifdef __cplusplus
}
#endif
#endif
As you can see, it's possible to implement that method in both C++ and C.
Let's review the implementation:
Code:
#include "JNITest.h"

JNIEXPORT jfloat JNICALL Java_JNITest_add
  (JNIEnv *env, jobject jobj, jfloat a, jfloat b) {
  return a + b;
}
The generated method has more two more parameters:
*env is a pointer to the JVM.
jobj is a reference to the method that called this native code
a and b are our float parameter we want to work with.
After that, you can create your shared library.
I'm using MinGW on Windows:
Code:
gcc -shared -Wl,--add-stdcall-alias -I JDK-HOME/include -I JDK-HOME/include/win32 JNITest.cpp -o JNITest.dll
If all files are saved in the same directory, you can run your application with "java JNITest". Otherwise you have to edit the java's library path.
HerrNuebel is offline  
Thanks
1 User
Old 06/26/2012, 19:22   #3
 
strontklit's Avatar
 
elite*gold: 0
Join Date: Mar 2012
Posts: 220
Received Thanks: 117
Thanks this is very usefull information!
strontklit is offline  
Reply


Similar Threads Similar Threads
[Information] Paradise Trainer
11/18/2010 - S4 League - 18 Replies
Sooo liebe leute da :O es ja einige Funny finden Pw zu leechen/Sharen oder sogar Tools zu machen die das erledigen, haben wir langsam :O kein Bock mehr! der Trainer Bleibt bis zum nexten Update von uns Deactiviert danke Könnt ihr Alle Pw Leecher oder Anti paradise Tool Creatoren... Gruß De4Su,-I.Paradise- ------- Well, guys :O since some guys are funny with leeching the pw or even making tools doing that, we're now fed up.
Request| Link for tsunami trainer (GC)
04/23/2009 - General Gaming Discussion - 1 Replies
title.. please soon as posible



All times are GMT +1. The time now is 09:23.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.