You are not logged in.

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

1

Saturday, January 10th 2009, 7:54pm

Audio Recording sample with NativeCall, Thread, Java-Calls, etc.

Hi fans of Jabaco!

Here is a sample which demonstrates some of the nice features of Jabaco:

- asynchronous threads

- calling external Windows routines via NativeCall

- calling Java framework classes and routines

- manipulating files

- calling user-defined Java routines

The sample is a little recording tool which writes microphone sound input to a WAV file. It was inspired by similar "SimpleAudioRecorder" programs on the net. Just for comparison, it implements the steps for sound processing in two different flavors. One is more oriented to the Microsoft VB style. The other is oriented to the Java sound processing style.

I came along one culprit when I tried to access a public internal class defined within a Java class:

The following does not work!
' Jabaco IDE does not seem to know internal classes of AudioFileFormat
' cf. http://java.sun.com/j2se/1.5.0/docs/api/….Type.html#WAVE
' Call AudioSystem.write(ais, AudioFileFormat.Type.WAVE, f)
To get around this problem, I wrote a small Java wrapper to call the method directly. There might be clever alternative ways to solve this. Who has a suggestion?

To compensate for the lack of documentation in Jabaco, I found Java decompilers useful. My favorite decompiler is http://java.decompiler.free.fr It is a great help to look at Jabaco.jar using this decompiler. Another choice could be "jad".

I'm not quite sure if I understand the exact usage of NativeCall() to access WIN32 API routines in external DLL libraries. However, I noticed that temporary DLL files "temp*.dll" are left behind in directory "%TEMP%" after termination of my demo program. The NativeCall implementation makes use of the File.deleteOnExit mechanism. Something must be strange here.

I hope you enjoy the sample and possibly report some hints and improvements here.

A1880
A1880 has attached the following file:
  • Jbmicvol.zip (10.17 kB - 867 times downloaded - latest: Mar 18th 2024, 6:36pm)

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

2

Sunday, January 11th 2009, 2:06am

Cool sample :thumbup:

Quoted

' Jabaco IDE does not seem to know internal classes of AudioFileFormat
Jabaco will support internal java classes in a future version ...

Quoted

There might be clever alternative ways to solve this. Who has a suggestion?
I'll fix this problem in Jabaco. So you need only a temporary workaround. Your solution is clever (in my mind) but if you don't like it you could try to find another solution with java reflections...

Quoted

I'm not quite sure if I understand the exact usage of NativeCall() to access WIN32 API routines in external DLL libraries.
Another solution to save your time:

Jabaco Source

1
2
3
4
5
6
Public WinApi Function mciSendString Lib "winmm.dll" _
  Alias "mciSendStringA" ( _
  ByVal lpstrCommand As String, _
  ByVal lpstrReturnString As String, _
  ByVal uReturnLength As Long, _
  ByVal hwndCallback As Long) As Long

Posts: 14

Date of registration: Feb 16th 2009

  • Send private message

3

Tuesday, February 17th 2009, 3:12pm

Hello,



NativeCall seems to have problems :/

The following code when executed do its call byt the returned value that is expected into va(3) gives cabbalistic values, instead of a string content... any idea ? 8|



Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Public Sub main(ByJava args() As String)
 
   Dim retStr As String 
   Dim va(0 To 5) As Variant 
   Dim res As Variant , i As Integer
   
   retStr = space(128)
   i = 128
   
   va(0) = "TEST"
   va(1) = "TEST"
   va(2) = "zz"
   va(3) = retStr
   va(4) = i
   va(5) = "C:\test.ini" 
   
   res = NativeCall("KERNEL32", "GetPrivateProfileStringA", va)
 
   msgbox va(3)
 
End Sub




Thanks

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Tuesday, February 17th 2009, 3:29pm

Output Parameters

Hi,
yes, I also haven't succeeded with output parameters.

see here

"NativeCall" and WINAPI probably need some more thoughts and some testing.

Due to Java's limitations (some would rather call it: "style") it is not directly possible to use output parameters.
One way around would be to pass a container object as parameter and call its setter method from within the called routine.
But this would obviously spoil the WINAPI syntax and would make WINAPI very much different from its VB6 predecessor,

Greetings!

A1880

Posts: 14

Date of registration: Feb 16th 2009

  • Send private message

5

Tuesday, February 17th 2009, 11:14pm

RE: Output Parameters

Hello,
Hi,
yes, I also haven't succeeded with output parameters.

see here

"NativeCall" and WINAPI probably need some more thoughts and some testing.

Due to Java's limitations (some would rather call it: "style") it is not directly possible to use output parameters.
One way around would be to pass a container object as parameter and call its setter method from within the called routine.
But this would obviously spoil the WINAPI syntax and would make WINAPI very much different from its VB6 predecessor,

Greetings!

A1880


Hemm... I come here as an original C developer and recently discovered a real use of Java, and have experimented JNI in C.

Just tell me if via a JNI interface one Api call is possible with in out parameters that can be then given back to the Java callee ?

If YES, then I've developped in C + ASM a GENERIC ApiCall engine I use through my language (FBSL) that I can share for the Jabaco project, but before I just want to see with a simple hard coded JNI C sample code how you can manage an in out value (if possible of course!), then I'll be able to help you with my generic api call engine!



Thanks

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

6

Wednesday, February 18th 2009, 7:25pm

NativeCall Holder Objects

Hi,
if I understand it right, the "NativeCall" mechanism is able to handle input and output parameters.
I looked at the original website of the inventor of NativeCall.
Unfortunately, he does not mention output parameters in his samples. But in the source code I came across "Holder" objects.
Such a Holder object acts as a data container to pass values back and forth between caller and callee.
The caller passes the Holder object to the callee. The callee in turn can call setter methods of the Holder to assign return values for
output parameters. It remains open to write an example to demonstrate and test this.

Jabaco generates NativeCall statement whenever you use WINAPI declarations in your Jabaco code.
My suspicion is that the case of output parameters has been overlooked.

Good luck!

A1880

A1880

Intermediate

  • "A1880" is male
  • "A1880" started this thread

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

7

Wednesday, February 18th 2009, 7:41pm

Holder object in Jabaco

Here is an illustrative sample

The Holder object as class clsHolder

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Option Explicit

Private myValue As Integer 

Public Sub clsHolder()
   '  constructor for initialization
   myValue = -1
End Sub

'  we are not using "properties".
'  This is just a demo for Holder objects ....

Public Function GetValue() As Integer 
   GetValue = myValue
End Function

Public Sub SetValue(i As Integer)
   myValue = i
End Sub


And here the code which demonstrates usage of Holder objects to implement two-way parameter passing:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Public Sub main(ByJava args() As String)
   Dim holder As clsHolder = New clsHolder
   Dim holderArray(0 To 5) As String 
   
   holderArray(1) = "hoo!"
   
   out.println "value before calling: " & holder.GetValue & " " & holderArray(1)
   
   Call Callee(holder, holderArray)
   
   out.println "value after calling: " & holder.GetValue  & " " & holderArray(1)   
   
   msgbox "ciao!"
End Sub

Private Sub Callee(holder As clsHolder, holderArray() As String)  ' "ByRef" nor "ByVal" make no difference here!
   holder.SetValue 5
   holderArray(1) = "ray!"
End Sub


I am wondering why "ByRef" and "ByVal" don't make a difference in this sample.

Any ideas?

A1880

This post has been edited 1 times, last edit by "A1880" (Feb 20th 2009, 4:01pm)


Gerome

Unregistered

8

Thursday, February 19th 2009, 9:56am

RE: Holder object in Jabaco

Hello,



It seems this code does not work and produces a JavaNullPointerException

Jabaco Source

1
2
Dim o As IntCall 
o = New IntCall( "kernel32", "CopyFileA" )




Is it a bug ?

Manuel

Administrator

  • "Manuel" is male

Posts: 256

Date of registration: Jul 16th 2008

Location: Erlangen, Germany

Occupation: Software Developer

Hobbies: Jabaco, game theory, text-mining

  • Send private message

9

Thursday, February 19th 2009, 2:36pm

Jabaco Source

1
2
3
Dim o As IntCall
   com#eaio#nativecall#NativeCall.init()
   o = New IntCall( "kernel32", "CopyFileA" )

Posts: 14

Date of registration: Feb 16th 2009

  • Send private message

10

Thursday, February 19th 2009, 9:15pm

Dear Manuel,

Many thanks!

Here's a complete code if this can help someone :

Jabaco Source

1
2
3
4
5
6
7
8
9
10
Public Sub Command1_Click() 
Dim o As IntCall 
Dim i As Integer 
Dim p(2) As String 
p(0) = "C:\Test.txt" 
p(1) = "C:\Test2.txt" 
com#eaio#nativecall#NativeCall.init() 
o = New IntCall( "kernel32", "CopyFileA" ) 
i = o.executeCall( p() ) 
End Sub

Rate this thread
WoltLab Burning Board