dotgnu-pnet
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pnet-developers] DLL's and language integration


From: Matthieu Cormier
Subject: [Pnet-developers] DLL's and language integration
Date: Sat, 16 Aug 2003 19:41:17 -0300 (ADT)

Hello,

Great work on portable .NET, I am a Mac OS X user and am happy to be able
to learn .NET without having to work on another machine.  I have installed
0.5.10
and compiled and run a couple of simple hello world type programs.

Of course, I have a question.  I just started reading .NET framework
Essentials and am currently working on  3.3 Language Integration.



What is my issue?
I am getting "car.vb:22: invalid throw expression" spit out at me from the
compiler.  Commenting out the throw line compiles my dll nicely but I
kinda want the throw in there and can't see anything wrong with the code.
It's also not my code, it's from the book .Net framework essentials.

-------------------Start car.vb--------------------------------
'
' HOW TO COMPILE:
'
'               cscc -c -shared -lVehicle.dll -o car.dll car.vb
Imports System

Public Class Car
        Inherits Vehicle

        Overrides Public Sub TurnLeft(  )
                Console.WriteLine("Car turns left.")
        End Sub

        Overrides Public Sub TurnRight(  )
                Console.WriteLine("Car turns right.")
        End Sub

        Public Overrides Sub ApplyBrakes(  )
                Console.WriteLine("Car trying to stop.")

                ' offending line comment out and compiler is happy
                throw new Exception ("Brake failure")
        End Sub

End Class

-----------------END car.vb ------------------------------

Vehicle.dll is a c# program which I've include below

----------------------- START Vehicle.cs ---------------------
/*
        HOW TO COMPILE:

                cscc -c -shared -o Vehicle.dll Vehicle.cs

*/
using System;


interface ISteering
{
        void TurnLeft(  );
        void TurnRight(  );
}

public abstract class Vehicle : ISteering
{



        public void TurnLeft(  )
        {
                Console.WriteLine("Vehicle turns left.");
        }

        public void TurnRight(  )
        {
                Console.WriteLine("Vehicle turns right.");
        }

        public abstract void ApplyBrakes(  );
}

------------------- END Vehicle.cs -----------------------

I'm not following the book exactly since the example in the book source
for Vehicle is written in managed C++, and I can't figure out how
to compile managed C++ with cscc.  Anyways, writing the whole thing in VB
with a prior example works fine.  Here is some sample code that compiles
to an executable with a main entry point (no language integration).

------------------ START ISteering.vb ------------------------
Imports System

Namespace Lang

        Interface ISteering
                Sub TurnLeft( )
                Sub TurnRight( )
        End Interface


        MustInherit Class Vehicle
                Implements ISteering

                Public Sub TurnLeft(  ) Implements ISteering.TurnLeft
                        Console.WriteLine("Vehicle turns left.");
                End Sub

                Public Sub TurnRight(  ) Implements ISteering.TurnRight
                        Console.WriteLine("Vehicle turns right.");
                End Sub

                Public MustOverride Sub ApplyBrakes(  )

        End Class

        Class Car
                Inherits Vehicle

                Public Overrides Sub ApplyBrakes(  )
                        Console.Writeline("Car trying to stop.")
                        throw new Exception ("Brake failure!")
                End Sub

        End Class

End Namespace

Public Module Driver

        Sub Main()

                Try

                        Dim v As Lang.Vehicle
                        v = New Lang.Car
                        v.TurnLeft()
                        v.ApplyBrakes()

                Catch e As Exception

                        Console.WriteLine(e.ToString() )

                End Try

        End Sub

End Module

------------------- END ISteering.vb -----------------------

Notice the similarities between the car class ApplyBrakes methods in
ISteering.vb and car.vb.  They are the same (except one is being compiled
to an executable and the other to a shared library).

I hope this is the correct list to ask questions about this, my
apologies if it is not, thanks.

Matthieu Cormier
================
Portfolio: http://www.cs.dal.ca/~mcormier/portfolio


reply via email to

[Prev in Thread] Current Thread [Next in Thread]