You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

1

Thursday, April 30th 2009, 6:24pm

It seems to be a bug in Jabaco with the API call MultiByteToWideChar

Hello Manuel,
if I use the following code in Visual Basic, I get the result I expected. If I use it in Jabaco, I get no result. Look at the code:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Private WinAPI Function MultiByteToWideChar Lib "kernel32.dll" ( _ 
ByVal CodePage As Long, ByVal dwFlags As Long, _ 
ByVal lpMultiByteStr As String, ByVal cchMultiByte As Long, _ 
ByVal lpWideCharStr As String, ByVal cchWideChar As Long) As Long

Private Const CP_ACP As Long = 0 

Dim Debug As New Debug 

Public Sub Command1_Click() 
  Dim t As String 
  Dim res As Long 
  Dim i As Long 

  res = MultiByteToWideChar(CP_ACP, 0, "Dies ist ein Test", _ 
    -1, 0, 0) 

  Debug.Print res 

  t = Space(res * 2 + 2) 

  MultiByteToWideChar CP_ACP, 0, "Dies ist ein Test", _
    Len("Dies ist ein Test"), t, Len(t) 

  For i = 1 To Len(t) 
    Debug.Print Mid(t, i, 1) 
  Next 

End Sub


In Visual Basic I get this result, in the direct window:

Source code

1
2
3
4
5
6
7
8
 18 
D 

i 

e 

s


In the Jabaco console I get only 18. I think there is something wrong - or do I make an error?

With the following workaround we can correct the problem:

Jabaco Source

1
2
3
4
5
6
7
8
9
Public Function JMultiByteToWideChar(Text As String) As String 
  Dim res As String = "" 
  For i = 1 To Len(Text) 
    res = res & Mid(Text, i, 1) 
    res = res & Chr(0) 
  Next 
  res = res & Chr(0) & Chr(0) 
  JMultiByteToWideChar = res 
End Function


Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

This post has been edited 2 times, last edit by "StefanSchnell" (Apr 30th 2009, 6:31pm)


A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Thursday, April 30th 2009, 6:45pm

No output parameters support yet

Hi Stefan,
if you look in the "temp" directory underneath the Jabaco program directory, you'll find the compiled Java classes of your example.
Decompiling the Form1.class yields the following:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    private long MultiByteToWideChar(long CodePage, long dwFlags, String lpMultiByteStr, long cchMultiByte, 
            String lpWideCharStr, long cchWideChar)
    {
        long MultiByteToWideChar = 0L;
        Exception Err = null;
        Exception h15 = null;
        VBA.VBArrayVariant vbarrayvariant = VBArray.createParamArray(5);
        vbarrayvariant.setValueVar(0, VBVariant.valueOf(CodePage));
        vbarrayvariant.setValueVar(1, VBVariant.valueOf(dwFlags));
        vbarrayvariant.setValueVar(2, VBVariant.valueOf(lpMultiByteStr));
        vbarrayvariant.setValueVar(3, VBVariant.valueOf(cchMultiByte));
        vbarrayvariant.setValueVar(4, VBVariant.valueOf(lpWideCharStr));
        vbarrayvariant.setValueVar(5, VBVariant.valueOf(cchWideChar));
        MultiByteToWideChar = Interaction.NativeCall("kernel32.dll", "MultiByteToWideChar", vbarrayvariant).longValue();
        return MultiByteToWideChar;
    }


There is no "way back" from NativeCall to copy the lpWideCharStr bytes into the variable of the calling routine.
So, you are right assuming that there is a bug. Jabaco's NativeCall implementation cannot handle output parameters.
You might want to have a look at the lengthy discussion on this subject which was posted a while ago.
Let's hope for the forthcoming release.

Greetings!

A1880

  • "StefanSchnell" is male
  • "StefanSchnell" started this thread

Posts: 102

Date of registration: Mar 13th 2009

Location: Oberirsen - Germany

Occupation: Senior Software Engineer

Hobbies: Programming aund Photography

  • Send private message

3

Thursday, April 30th 2009, 6:52pm

Hello A1880,
thanks for the clearing-up.
Cheers
Stefan
Visit my personal or commercial site
If you have questions or suggestions, write me an eMail or
meet me here

OlimilO

Intermediate

  • "OlimilO" is male

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

4

Thursday, April 30th 2009, 8:56pm

why not use javas built in encoding instead?

Hello you both,



Oh come on, in Jabaco there is simply no need for this WinAPI-function, because Java already has encoding.

Just google for "Java encoding".



Cheers OlimilO

Rate this thread
WoltLab Burning Board