Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » How to convert a java String into a pointer
How to convert a java String into a pointer [message #450056] Mon, 07 February 2005 09:40 Go to next message
kite is currently offline kiteFriend
Messages: 34
Registered: July 2009
Member
Hi ,

I have try to use OS class to access my win32 dll , I can successfully for
most case using SendMessage method ,but when I want to wParam as a String
, I cann't. Maybe I need to convert a java string as a pointer (java int)
, anyone know how to convert a java string as a sz String pointer? For
example ,
my dll code snippet is :
case SCI_SETPROPERTY:
props.Set(reinterpret_cast<const char
*>(wParam),reinterpret_cast<const char *>(lParam));
break;

My java code is :
OS.SendMessage(int hwnd,int msg,int wParam,byte[] lParam);

Thanks.
Re: How to convert a java String into a pointer [message #450061 is a reply to message #450056] Mon, 07 February 2005 11:55 Go to previous messageGo to next message
Robert Bacs is currently offline Robert BacsFriend
Messages: 165
Registered: July 2009
Senior Member
Hi,

You need to convert your String object in TCHAR object, just create a TCHAR
object using TCHAR (int codePage, String string, boolean terminate)
constructor, and then when you need a pointer just access the chars member
(for Unicode) or bytes member (for non-Unicode).

Regards,
Boby

"Kite" <yipeng97@yahoo.com> wrote in message
news:cu7d1n$a4s$1@www.eclipse.org...
> Hi ,
>
> I have try to use OS class to access my win32 dll , I can successfully for
> most case using SendMessage method ,but when I want to wParam as a String
> , I cann't. Maybe I need to convert a java string as a pointer (java int)
> , anyone know how to convert a java string as a sz String pointer? For
> example ,
> my dll code snippet is :
> case SCI_SETPROPERTY:
> props.Set(reinterpret_cast<const char
> *>(wParam),reinterpret_cast<const char *>(lParam));
> break;
>
> My java code is :
> OS.SendMessage(int hwnd,int msg,int wParam,byte[] lParam);
>
> Thanks.
>
Re: How to convert a java String into a pointer [message #450094 is a reply to message #450061] Mon, 07 February 2005 20:17 Go to previous messageGo to next message
Steve Northover is currently offline Steve NorthoverFriend
Messages: 1636
Registered: July 2009
Senior Member
Be warned that you are using internal API that is subject to change. For
example, TCHAR was added around 2.0.

"Robert Bacs" <boby@zerosoft.ro> wrote in message
news:cu7kvl$beg$1@www.eclipse.org...
> Hi,
>
> You need to convert your String object in TCHAR object, just create a
TCHAR
> object using TCHAR (int codePage, String string, boolean terminate)
> constructor, and then when you need a pointer just access the chars member
> (for Unicode) or bytes member (for non-Unicode).
>
> Regards,
> Boby
>
> "Kite" <yipeng97@yahoo.com> wrote in message
> news:cu7d1n$a4s$1@www.eclipse.org...
> > Hi ,
> >
> > I have try to use OS class to access my win32 dll , I can successfully
for
> > most case using SendMessage method ,but when I want to wParam as a
String
> > , I cann't. Maybe I need to convert a java string as a pointer (java
int)
> > , anyone know how to convert a java string as a sz String pointer? For
> > example ,
> > my dll code snippet is :
> > case SCI_SETPROPERTY:
> > props.Set(reinterpret_cast<const char
> > *>(wParam),reinterpret_cast<const char *>(lParam));
> > break;
> >
> > My java code is :
> > OS.SendMessage(int hwnd,int msg,int wParam,byte[] lParam);
> >
> > Thanks.
> >
>
>
Re: How to convert a java String into a pointer [message #450103 is a reply to message #450061] Tue, 08 February 2005 05:05 Go to previous messageGo to next message
kite is currently offline kiteFriend
Messages: 34
Registered: July 2009
Member
Hi , Robert

Thanks for your answer. I have try it , but I need a int value to
represent a pointer because OS.SendMessage(int hwnd,int msg,int wParam,int
lParam) method need a int value for wParam , so if no other approach to
do these , we have to modify c++ code.

Thanks.

Robert Bacs wrote:

> Hi,

> You need to convert your String object in TCHAR object, just create a TCHAR
> object using TCHAR (int codePage, String string, boolean terminate)
> constructor, and then when you need a pointer just access the chars member
> (for Unicode) or bytes member (for non-Unicode).

> Regards,
> Boby

> "Kite" <yipeng97@yahoo.com> wrote in message
> news:cu7d1n$a4s$1@www.eclipse.org...
>> Hi ,
>>
>> I have try to use OS class to access my win32 dll , I can successfully for
>> most case using SendMessage method ,but when I want to wParam as a String
>> , I cann't. Maybe I need to convert a java string as a pointer (java int)
>> , anyone know how to convert a java string as a sz String pointer? For
>> example ,
>> my dll code snippet is :
>> case SCI_SETPROPERTY:
>> props.Set(reinterpret_cast<const char
>> *>(wParam),reinterpret_cast<const char *>(lParam));
>> break;
>>
>> My java code is :
>> OS.SendMessage(int hwnd,int msg,int wParam,byte[] lParam);
>>
>> Thanks.
>>
Re: How to convert a java String into a pointer [message #450105 is a reply to message #450103] Tue, 08 February 2005 10:12 Go to previous messageGo to next message
Robert Bacs is currently offline Robert BacsFriend
Messages: 165
Registered: July 2009
Senior Member
Hi,

If you use the OS from SWT you can call the

SendMessage (int hWnd, int Msg, int wParam, TCHAR lParam)

method (this is much more simple), but if you want to implement yourself the
JNI method then you should do the following:

- declare two native methods:
public static final native int SendMessageA (int hWnd, int Msg, int
wParam, byte [] lParam);
public static final native int SendMessageW (int hWnd, int Msg, int
wParam, char [] lParam); // for unicode version

- declare a Java method:
public static final int SendMessage (int hWnd, int Msg, int wParam,
TCHAR lParam) - this will call the native methods

- in your JNI code you will need to convert your bytearray argument in a
pointer - you will use the GetByteArrayElements() method for this.

If you need help for the above steps you can look at the SWT source code: OS
class and JNI code os.c file.

Hope this helps !

Regards,
Boby



"Kite" <yipeng97@yahoo.com> wrote in message
news:cu9hbj$4hv$1@www.eclipse.org...
> Hi , Robert
>
> Thanks for your answer. I have try it , but I need a int value to
> represent a pointer because OS.SendMessage(int hwnd,int msg,int wParam,int
> lParam) method need a int value for wParam , so if no other approach to
> do these , we have to modify c++ code.
>
> Thanks.
>
> Robert Bacs wrote:
>
> > Hi,
>
> > You need to convert your String object in TCHAR object, just create a
TCHAR
> > object using TCHAR (int codePage, String string, boolean terminate)
> > constructor, and then when you need a pointer just access the chars
member
> > (for Unicode) or bytes member (for non-Unicode).
>
> > Regards,
> > Boby
>
> > "Kite" <yipeng97@yahoo.com> wrote in message
> > news:cu7d1n$a4s$1@www.eclipse.org...
> >> Hi ,
> >>
> >> I have try to use OS class to access my win32 dll , I can successfully
for
> >> most case using SendMessage method ,but when I want to wParam as a
String
> >> , I cann't. Maybe I need to convert a java string as a pointer (java
int)
> >> , anyone know how to convert a java string as a sz String pointer? For
> >> example ,
> >> my dll code snippet is :
> >> case SCI_SETPROPERTY:
> >> props.Set(reinterpret_cast<const char
> >> *>(wParam),reinterpret_cast<const char *>(lParam));
> >> break;
> >>
> >> My java code is :
> >> OS.SendMessage(int hwnd,int msg,int wParam,byte[] lParam);
> >>
> >> Thanks.
> >>
>
>
Re: How to convert a java String into a pointer [message #450441 is a reply to message #450105] Sat, 12 February 2005 03:20 Go to previous message
kite is currently offline kiteFriend
Messages: 34
Registered: July 2009
Member
Hi ,

Thanks. I have tried all method SendMessage(). My question is not about
lParam , yes , I can use byte[] , TCHAR to pass my java String. But MY
QUESTION IS ABOUT - wParam , how to send a java String as int?

Thanks.

Robert Bacs wrote:

> Hi,

> If you use the OS from SWT you can call the

> SendMessage (int hWnd, int Msg, int wParam, TCHAR lParam)

> method (this is much more simple), but if you want to implement yourself the
> JNI method then you should do the following:

> - declare two native methods:
> public static final native int SendMessageA (int hWnd, int Msg, int
> wParam, byte [] lParam);
> public static final native int SendMessageW (int hWnd, int Msg, int
> wParam, char [] lParam); // for unicode version

> - declare a Java method:
> public static final int SendMessage (int hWnd, int Msg, int wParam,
> TCHAR lParam) - this will call the native methods

> - in your JNI code you will need to convert your bytearray argument in a
> pointer - you will use the GetByteArrayElements() method for this.

> If you need help for the above steps you can look at the SWT source code: OS
> class and JNI code os.c file.

> Hope this helps !

> Regards,
> Boby



> "Kite" <yipeng97@yahoo.com> wrote in message
> news:cu9hbj$4hv$1@www.eclipse.org...
>> Hi , Robert
>>
>> Thanks for your answer. I have try it , but I need a int value to
>> represent a pointer because OS.SendMessage(int hwnd,int msg,int wParam,int
>> lParam) method need a int value for wParam , so if no other approach to
>> do these , we have to modify c++ code.
>>
>> Thanks.
>>
>> Robert Bacs wrote:
>>
>> > Hi,
>>
>> > You need to convert your String object in TCHAR object, just create a
> TCHAR
>> > object using TCHAR (int codePage, String string, boolean terminate)
>> > constructor, and then when you need a pointer just access the chars
> member
>> > (for Unicode) or bytes member (for non-Unicode).
>>
>> > Regards,
>> > Boby
>>
>> > "Kite" <yipeng97@yahoo.com> wrote in message
>> > news:cu7d1n$a4s$1@www.eclipse.org...
>> >> Hi ,
>> >>
>> >> I have try to use OS class to access my win32 dll , I can successfully
> for
>> >> most case using SendMessage method ,but when I want to wParam as a
> String
>> >> , I cann't. Maybe I need to convert a java string as a pointer (java
> int)
>> >> , anyone know how to convert a java string as a sz String pointer? For
>> >> example ,
>> >> my dll code snippet is :
>> >> case SCI_SETPROPERTY:
>> >> props.Set(reinterpret_cast<const char
>> >> *>(wParam),reinterpret_cast<const char *>(lParam));
>> >> break;
>> >>
>> >> My java code is :
>> >> OS.SendMessage(int hwnd,int msg,int wParam,byte[] lParam);
>> >>
>> >> Thanks.
>> >>
>>
>>
Previous Topic:JFace Dialog Sizing and Form Layout
Next Topic:control height fro toolbar image
Goto Forum:
  


Current Time: Thu Apr 25 11:44:34 GMT 2024

Powered by FUDForum. Page generated in 0.03241 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top