DLL does not work from VBA

Started by neuwirthe, September 16, 2004, 12:24:10 AM

Previous topic - Next topic

neuwirthe

#15
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.

neuwirthe

#16
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

HPW

#17
I think Lutz will be interested in the demo-code.

(Send it to 'lutz at nuevatec dot com' and put newlisp in the subject)

Until Lutz has put it on the server, you could also send it to my mail.

(hpwickern at hpwsoft dot de)

Thanks again for working it out.

This is one more sample for the practical use of newLISP for real world work.
Hans-Peter

Lutz

#18
Hi Erich,



You can send the zip file to me: lutz at nuevatec dot com . put the word 'newlisp' in the subject line, so it will not be eaten by my spam filters. I can than link to it from the 'Code Contributions' section.



Or if you can host it yourself, I can link to it.



Lutz



ps: oops, looks like HPW's and my brain worked in sync on this

neuwirthe

#19
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

HPW

#20
I have a working VB.NET example posted here and as I posted, found to have problems with the GCC-compiled version of newLISP.dll

It was working with the BCC-compiled flavor. So interested should use this flavor until we found out what the problem could be.
Hans-Peter

neuwirthe

#21
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.

HPW

#22
>Have you done extensive testing with the BC compiled version?



Not realy! Was only simple testing with calling one simple function again an again.

GCC crashed with the third call. BCC run a lot calls without problems, but I did not count. More testing have to be done if their is interest to run under .NET. My interest for the moment is to do testing for the WINCE-port as soon I get some hardware.
Hans-Peter

neuwirthe

#23
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

HPW

#24
Erich,



Thanks again for this.

I will give it a try.
Hans-Peter

HPW

#25
I have tested your code but I get errors.

Which versions of visual studio/VB.NET and framework are you using?



Also note that this is the old EntryPoint:="dllEvalStr".

The new is EntryPoint:="newlispEvalStr"
Hans-Peter

HPW

#26
Erich,



I have got your sample code and only start 'NewLispDotNet.exe' from the bin-folder. I get the sample form and type '(setq a 5)' and hit 'Evaluate'. Then I hit it a second and a third time. First and second return 5. With the third hit I get:



System.NullReferenceException: Der Objektverweiss wurde nicht auf eine Objektinstanz festgelegt.

at NewLispDotNet.Form1.dllNewlispeval(String txt)

...

...



Then I compiled the latest 8.2.0 source to a BCC-DLL and replace the GCC-DLL with it. Then I could use your VB.NET sample without problem.
Hans-Peter

HPW

#27
In current:



http://www.newlisp.org/code/NewLispDotNet.zip">http://www.newlisp.org/code/NewLispDotNet.zip



in Module1.vb is the deprecated 'dllEvalStr' used instead of 'newlispEvalStr'.

Not yet a problem but maybe in the future.
Hans-Peter