Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - neuwirthe

#1
newLISP Graphics & Sound / MIDI controllers
June 25, 2008, 03:33:27 PM
Only today I found out about the MIDI stuff in guiserver, and I really like it. Currently only note and pitch bend seem to be supported. Are there plans to also implement controllers (technically, that is rather easy). It would allow to

implement sounds from moving sound sources and other interesting projects.
#2
newLISP and the O.S. /
September 26, 2004, 09:08:58 AM
Here is VB.NET code working with h GCC compiled version.



Public Class Form1

    Inherits System.Windows.Forms.Form





    <DllImport("c:newlispnewlisp.dll", _

               EntryPoint:="dllEvalStr", _

               CharSet:=CharSet.Ansi, _

               CallingConvention:=CallingConvention.StdCall)> _

    Public Shared Function dllNewlispeval(ByVal txt As String) As System.Text.StringBuilder

        ' Leave function empty - DLLImport attribute forwards calls to newlisp

    End Function



    Public Shared Function NewLisp(ByVal LispExpression As String) As String

        Dim ResultObject As System.Text.StringBuilder

        ResultObject = dllNewlispeval(LispExpression)

        Return ResultObject.ToString

    End Function





    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim RetVal As String ' Stores the return value.

        Try

            TextBox2.Text = NewLisp(TextBox1.Text)

        Catch ex As Exception           ' Catch the error.

            MsgBox(ex.ToString)         ' Show friendly error message.

        End Try

    End Sub



#Region " Windows Form Designer generated code "

#I do not include this code

#End Region



End Class
#3
newLISP and the O.S. /
September 25, 2004, 02:58:27 PM
I was using your VB.NET example as a starter.

Have you done extensive testing with the BC compiled version?

I fear that it might have the same problems lik the GCC version

in a longer run.

Therefore, I think it would be worthwhile to adapt the lstrCpy method

to VB.NET also. but I have not found a way of doing this.
#4
newLISP and the O.S. /
September 25, 2004, 12:37:13 PM
I just tried to adapt the WinAPI technique to the VB.NET example, and it does not work at all. I do not know VB.NET. Perhaps you can try to convert the VB6 technique to VB.NET? Maybe this takes care of the crashes in VB.NET
#5
newLISP and the O.S. /
September 25, 2004, 12:01:54 PM
Some more things:

Strings in VB are rather difficult, there is a special type BSTR which has to be used in C programs to be called by VB, but support for this type seems only to be supplied for Microsoft compilers. Therefore I am using a workaround calling WinAPI functions converting C's char * to VB strings.



Another thing: if you like Excel, try to have a look at my book



The Active Modeler - Mathematical Modeling with Microsoft Excel

Erich Neuwirth - University of Vienna (Austria)

Deane Arganbright - University of Tennessee, Martin

ISBN 0534420850
#6
newLISP and the O.S. /
September 25, 2004, 11:37:19 AM
is there some repository where I can put examples? I now have VB6 and Excel examples as zip files.



About LoadNewLISP:

Your code works with a fixed path to newlisp. LoadNewLISP in the new examples will pompt you for its location when it is not found immediately.



I also think that as long as newlisp.dll is on the path, LoadNewLISP is not necessary. But I think it helps people if you show them how to handle a somehwat more difficult situation.
#7
newLISP and the O.S. / Problem solved
September 16, 2004, 08:13:56 AM
Thats the way it works in VBA:



Create a module in Excel's VBA editor.

Paste the code below.

Put the cursor inside the sub test

Press F5



Now we have NewLISP in Excel!!!!!!!!!!!!!!!!!!!!!!!!!!!!

More code to follow





Public Declare Function dllEvalNewLISP Lib "newlisp" Alias "newlispEvalStr" ( _

    ByVal LExpr As String) As Long

Private Declare Function lstrLen Lib "kernel32" Alias "lstrlenA" ( _

    lpString As Any) As Long

Private Declare Function lstrCpy Lib "kernel32" Alias "lstrcpyA" ( _

    lpString1 As Any, lpString2 As Any) As Long

Private Declare Function LoadLibraryA Lib "kernel32" (ByVal s As String) As Long

Private Declare Sub FreeLibrary Lib "kernel32" (ByVal h As Long)

Dim NewLISPhandle As Long



Sub LoadNewLISP()

    On Error Resume Next

    Dim mylib As String

    mylib = ThisWorkbook.Path & "newlisp.dll"

    NewLISPhandle = LoadLibraryA(mylib)

    Debug.Print NewLISPhandle

End Sub



Sub UnloadNewLISP()

    On Error Resume Next

    FreeLibrary (NewLISPhandle)

End Sub





Function EvalNewLISP(LispExpression As String) As String

    Dim resHandle As Long

    Dim result As String

    resHandle = dllEvalNewLISP(LispExpression)

    result = Space$(lstrLen(ByVal resHandle))

    lstrCpy ByVal result, ByVal resHandle

    EvalNewLISP = result

End Function



Sub test()

    LoadNewLISP

    MsgBox EvalNewLISP("(* 56 56)")

    UnloadNewLISP

End Sub
#8
newLISP and the O.S. /
September 16, 2004, 06:21:32 AM
http://support.microsoft.com/default.aspx?scid=kb;en-us;187912">http://support.microsoft.com/default.as ... -us;187912">http://support.microsoft.com/default.aspx?scid=kb;en-us;187912

has a description of how to pass strings between VB6 (also applies to VBA) and a C dll.

I think this mandates a 2 step process.

Evaluate in the DLL and assign to a temporary buffer.

Let VB call a function giving the size of the string in VB.

Allocates string in VB. Call C DLL to fil VB buffer.

I volunteer for the VBA testing. Can somebody try to implement

this mechanism in the C DLL?

I am not good enough in C to do it.

I think it would be VERY important to be able to call NewLISP

in office apps, especially in Excel.
#9
newLISP and the O.S. /
September 16, 2004, 04:14:35 AM
I do not have BCC, and i had the same problem when I tried your

VB.NET example.
#10
This is getting really messy.

The problem is that VB and VBA cannot handle char * as return values,

strings work differently in VB.

I am investigating if it can be done.

I read the mentioned thread.

VB and VBA use stdcall, that is not the issue.

I added a test function returning integers

declared with DLLCALL to win32dll.c and it worked.



In VBA, one cannot declare the calling convention.



I already posted on microsoft.public.vb.general.discussion

to see if somebody knows how to write a C function

returning VB-usable strings.
#11
newLISP and the O.S. / DLL does not work from VBA
September 16, 2004, 12:24:10 AM
I tried do use the DLL in Excel through VBA.

It does not work, it crashes.

I have used similar code for other DLLs, so I assume the

signature of newlispEvalStr is not right.

Loading works, I get a handle on the DLL

(there is code to check that!)



Public Declare Function EvalNewLISP Lib "newlisp" Alias "newlispEvalStr" (ByVal LExpr As String) As String

Private Declare Function LoadLibraryA Lib "kernel32" (ByVal s As String) As Long

Private Declare Sub FreeLibrary Lib "kernel32" (ByVal h As Long)

Dim NewLISPhandle As Long



Sub LoadNewLISP()

    On Error Resume Next

    Dim mylib As String

    mylib = ThisWorkbook.Path & "newlisp.dll"

    NewLISPhandle = LoadLibraryA(mylib)

    MsgBox NewLISPhandle

End Sub



Sub UnloadNewLISP()

    On Error Resume Next

    FreeLibrary (NewLISPhandle)

End Sub





Sub test()

    LoadNewLISP

    MsgBox EvalNewLISP("(+ 2 3)")

    UnloadNewLISP

End Sub
#12
newLISP and the O.S. / minibug witn win32 installation?
September 15, 2004, 07:34:05 AM
I installed newlisp in c:mathstatnewlisp, and now

Help -> Manual and Reference does not work because it still tries

to find the files in c:newlisp