compiling C# to a DLL

Archives Forums/Blitz3D SDK Programming/compiling C# to a DLL

dynaman(Posted 2007) [#1]
I'm trying to compile the C# header to a dll so I can Import it to my VB.NET project. I manage to compile the DLL but when I import it I am not able to use it. Anyone have pointers on what I'm doing wrong?


ziggy(Posted 2007) [#2]
It could be something releated to namespaces. I have a compiled dll version for use with Visual Basic.net


dynaman(Posted 2007) [#3]
I took the original C# blitz3dsdk class file and tried to compile it as a C# dll. Did I need to change the name of the namespace?

The steps I took.
1 - I created a C# Class Library project and called it blitz3dsdk.
2 - I copied the existing namespace from the blitz3dsdk into it.
3 - Compiled to a DLL
4 - Referenced in a VB project. It shows up in the list but I can't make use of it.

Should I use a different name for the namespace or C# project name?

I'd ask for a copy of the dll, but I'm not sure that is legal.


Daz(Posted 2007) [#4]
If you are still having problems creating your DLL you could try converting the c# headers directly to the VB.NET equivalent.

If you download the free SharpDevelop IDE,
http://sourceforge.net/project/downloading.php?groupname=sharpdevelop&filename=SharpDevelop_2.1.0.2429_Final.msi&use_mirror=kent

There is a function in there (Tools Menu -> Convert To) which will convert C# code to VB.NET code.

I haven't had a chance to test the conversion yet, but if it works, at least it means you don't have to have an a second DLL.


dynaman(Posted 2007) [#5]
Daz:
I gave that a try, and it doesn't work with the DLL stuff. I have done a good bit of manually already, but it has taken 6 hours or so at this point and I'm roughly 80% done.

VB does not like the static class, so I changed that to a module. The converter also had trouble with the const statements, they were easy enough to convert though. It is going through the dll"B3D" stuff that is time consuming.

Only thing I'm worrying about (other then typos) is if the wrapper changes I'd have to go through and upgrade again, yuck...


ziggy(Posted 2007) [#6]
Static is shared on Visual Basic.


Daz(Posted 2007) [#7]
Hi Dynaman,

I have tried converting the .cs header to VB.NET code using SharpDevelop converter and it worked. That bit took about a minute to do.

The only code change I had to do with the SharpDevelop IDE converted code was change the Private to Public for the new method.

Here is the code I wrote to test the VB.NET header conversion - this example is rendering to a picture box control:

Public Class Form1
    Public blitz = New Blitz3DSDK
    Dim cube, light, camera As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        blitz.SetBlitz3DHWND(PictureBox1.Handle.ToInt32())

        blitz.BeginBlitz3D()
        blitz.Graphics3D(PictureBox1.Width, PictureBox1.Height, 0, 2)

        cube = blitz.CreateCube(0)
        light = blitz.CreateLight(1, 0)
        camera = blitz.CreateCamera(0)
        blitz.PositionEntity(camera, 0, 0, -4, 1)

        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        blitz.UpdateWorld(1)
        blitz.RenderWorld(0)
        blitz.TurnEntity(cube, 0.1F, 0.2F, 0.3F, 1)
        blitz.Text(20, blitz.GraphicsHeight() - 20, "Blitz3d SDK C# example to use a panel control", 0, 0)
        blitz.Flip(1)
    End Sub
End Class


So, all in all, the complete process only took me about 10 mins.


dynaman(Posted 2007) [#8]
I must have been using a different version then. I'll give the one you listed a try.

Very nice.


[EDIT] Thanks to you too Ziggy.


Daz(Posted 2007) [#9]
There are two versions of SharpDevelop - one for .NET framework 1 and one for .NET framework 2. I don't know if it makes any difference but I used the version for .NET framework v2.


dynaman(Posted 2007) [#10]
That did the trick. I've gotten everything up and running now. Thanks for all the help.

Perhaps VB.NET headers and examples could be included in the next update/bugfix.


Daz(Posted 2007) [#11]
No problem. Glad to help.

I agree about the VB.NET headers being include. In fact,, I just sent off the VB.NET headers and an example to the team. So, maybe they will include it in the next update/future versions.


Rone(Posted 2007) [#12]
hi,
why not compiling it to an .net component .dll with a nice properties box?
This could be used in all .net languages without making a wrapper for each language...

I quite recently have done that with ActivVisionTools and HalconX. It seems to be the best professional solution.


ziggy(Posted 2007) [#13]
Maybe that's becouse in this case it is not a control, as a static library, it can't have multiple instances of itself, so making it a control is not possible. Maybe it could be done as a .net DLL so you can use the SDK with C#, with VB .net and, if it is the case, with both of them in the same project.


Dreamora(Posted 2007) [#14]
the approach of .NET DLL would even open it to a wider audience ... Delphi.NET and Eiffel (.NET projects)
both interesting languages where many would be interested in game creation but due to the small audience there is little possibility to do so.


Dazza(Posted 2007) [#15]
In addition to the sample code above, I would suggest that you change the following if you are going to use the code as a basis for further developing code...

1) Ensure you have...
    Option Strict On
at the top of each class module. It will annoy the heck out of you when you are compiling, but when you come to debug you will be glad you did!


2) To get full intellisense (and because Option Strict will complain anyway!) change the SDK object declaration to:
    Public blitz As Blitz3DSDK = New Blitz3DSDK



Kanati(Posted 2007) [#16]
the better way (though there's a ton of different ways) would be to declare it:

Public blitz As New Blitz3DSDK


What Dazza is saying though is correct. In your original declaration, you are basically creating blitz as a variant which is then assigned the new object of blitz3dsdk. By declaring it AS blitz3dsdk you gain the benefits of intellisense.


Kanati(Posted 2007) [#17]
man... I had to go through and make all the public shared functions not shared... and I'm probably going to make the bb functions private so they don't show up in intellisense as well. Not as easy as just a convert tool over here. :/


Shayde(Posted 2007) [#18]
I also am very interested in VB.NET (both 2003 & 2005) examples and header. I use 2003 at work mostly so I lean in that direction most. Having some trouble with converting the C# examlpes myself (complaining about missing Namespace etc.). Tried converting the Blitz3DSDK.cs to .vb using both the SharpDev tool and several C# to VB.NET converters on the Internet. All bust. Or maybe one of you smart fellas can put together a little Tut for us mere mortals. I'd really like to see the VB.NET example in the next update.