|
-
Jun 14th, 2002, 08:46 AM
#1
Casting data type...please help
#define UNICODE
#include <jni.h>
#include "AcrobatFile.h"
#include <windows.h>
void launchAcrobat(char fileName[256]);
JNIEXPORT void JNICALL Java_AcrobatFile_PrintAcrobatFile
(JNIEnv *env, jobject obj, jstring fileName)
{
char acrobatFileName[256];
acrobatFileName = env->GetStringChars(fileName,0);
launchAcrobat(acrobatFileName);
acrobatFileName = env->ReleaseStringChars(fileName,acrobatFileName);
}
I'm trying to make the following code work but i keep getting the following errors
[ error C2440: '=' : cannot convert from 'const unsigned short *' to 'char [256]'
[error C2664: 'ReleaseStringChars' : cannot convert parameter 2 from 'char [256]' to 'const unsigned short *'
My question is. How do i convert acrobatFileName[256] to a const unsigned short *? Really appreciate the help. Been stuck on this for a while now. Thanks!
-
Jun 14th, 2002, 09:36 AM
#2
Frenzied Member
If you declare a string as an array of characters on the stack, like this:
Code:
char acrobatFileName[256];
then what you have actually done is reserved 256 bytes on the stack for your app, and got yourself a constant pointer to the first byte.
You can't just reassign arrays using the = operator. You have to assign each element individual, or copy a whole block of memory over, or use a utility function (like strcpy() for instance) to do it for you.
Anyway, it seems you are also having some type problems.
char[] is in this case actually exactly the same as const unsigned short *, on 32 bit Windows at least. You should be able to do a simple cast in this case to let the compiler know that you know what you're doing:
Code:
strcpy(acrobatFileName, (char *)(env->GetStringChars(fileName,0)));
You may need to include string.h to get the strcpy() function.
Harry.
"From one thing, know ten thousand things."
-
Jun 14th, 2002, 10:22 AM
#3
Monday Morning Lunatic
Don't you have to use Unicode with Java? That would explain the "short" part of it...
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jun 16th, 2002, 05:37 PM
#4
parksie hit it straight:
Code:
void launchAcrobat(wchar_t *fileName);
JNIEXPORT void JNICALL Java_AcrobatFile_PrintAcrobatFile
(JNIEnv *env, jobject obj, jstring fileName)
{
wchar_t acrobatFileName[256];
acrobatFileName = env->GetStringChars(fileName,0);
launchAcrobat(acrobatFileName);
acrobatFileName = env->ReleaseStringChars(fileName,acrobatFileName);
}
You must use UNICODE characters.
Harry: those are NOT the same, never have been and never will be. Don't make that mistake, it can cause strange and hard-to-find errors.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|