Question subject: passing string value from java to .exe file
Posted: Wed Oct 22, 2008 1:08 am
Joined: Sun Oct 19, 2008 3:47 pm Posts: 281 Has thanked: 0 time Have thanks: 1 time
Dear All,
I'm having a problem to pass values from .class file to .exe file. perhaps I search all corresponding dll files but I can able to know the function. but I don't know how to pass values, I keep on searching If anybody did such type of enhancement pls guide me
AnswerBot
Question subject: Re: passing string value from java to .exe file
Posted: Wed Oct 22, 2008 1:09 am
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
Do you know JNI? This will let you interface Java to C/C++. If the .exe file already exists, JNI will help put the String in a format that can be sent across.
The other thing is to realize what a C/C++ string is an array of characters (same as Java bytes) followed by \0
So,
Code:
char *test = "abcde";
is the same as
Code:
char *test = malloc (6); test [0] = 'a'; test [1] = 'b'; test [2] = 'c'; test [3] = 'd'; test [4] = 'e'; test [5] = '\0';
Use the getBytes () method of String to get a byte array representation of the String, and then add on the character \0. C will recognize this.