[.net] VB.Net and cross-platformness

Started by
15 comments, last by nagromo 18 years, 11 months ago
Quote:Original post by Seroja
Why make it in VB:
1) Kind of a challenge for myself - to see if I can make it ALL by myself.
2) Have the whole program written in one language.
3) Have it in as global functions, and not as functions of a class.
4) Be able to change anything I want (though not really relevant as they make it work, but still makes me feel better, hate stuff I can't change crash).

That's your choice. It seems like a lot of work to get it up and running and fixing bugs to get it working reliably on all platforms when Tao's already doing the same thing, but hey...

Quote:
I need Marshal only for pointers. VB doesn't have them properly, so I use stuff like PtrToStringAnsi. I guess there could be a way around this by using dummy functions and ByRef, but Marshal works well until now.

Marshal doesn't work?!?! I use Marshal.Copy when loading textures and my program works fine on Linux! Maybe it's more recently added, but I know Marshal.Copy works on Mono 1.0.5.

You should only need pointers for interacting with the underlying API, but the wrapper exposing it as a .Net function should handle that. Even if you write your own wrapper, that should be the only place you need pointers. That's if you're writing your wrapper like Tao, which to your app treats them as .Net types (I.E. glGetString would return a System.String instead of a char[]). If you write your wrapper in that style, it will be easier to use as you only do the conversions in one place isntead of everywhere you use the function.

Quote:
About WinForms, any example on creating cross-platform forms in VB? The best I can do is open a form in C-style, through API calls. But that would still be a WinForm. Or are there APIs like CreateWindow on all platforms?

If you want to write cross-platform WinForms, you should write your code on Mono and only use things that work on Mono. That will be extremely limiting, though.

You could also use a cross-platform library like GTK#. I think that would need to be installed to run on Windows, though. With GTK# you can use the stand-alone program Glade to design your windows and load that file into your .Net app to create the window at runtime. I've messed around with it a bit in C# on Linux; it's not too complicated.

Quote:
And it *might* work on one compile, I think VB allows to declare functions that don't exist and doesn't throw an error as long as you don't try to use them.

As a side note, what is faster, Win32 API or .Net framework? I mean, there are many functions that are present in both, e.g. TicksCount. I know I should use .Net for cross-platformness, but won't that slow me down?

In general, good .Net code should get ~95% of the speed of good C++ code. I don't know how that changes with win32 and WinForms, but remember that on Longhorn win32 will be legacy code, even moreso than WinForms.

Alternatively, if you choose to use GTK#, they will probably eventually write a new version that runs directly on top of the Longhorn API.
Advertisement
.Net is good for the future :)

Weird about Marshal, I looked a few days ago, it said to be added later. I'll recheck that. I use it that way:

Public Declare Function glGetString Lib "opengl32.dll" (ByVal name As UInteger) As Integer

Public Function vbglGetString(ByVal name As UInteger) As String
tmpIntPtr = New IntPtr(glGetString(name))
Return PtrToStringAnsi(tmpIntPtr)
End Function

Thought there might be a better way.

I'll try to use GTK#, I'll see what it is.

Thanks for the info.
BTW, Mono WinForms (MWF) has come a long way. It's currently listed at 93% completion. Check out the MWF blog if you'd like to know more.
Yay, it looks like 97% already! (which is enough for me, they seem to have trouble with several controls, but I don't use any :)

BTW, what's the .Net alternative to GetDC API (if any)? I tried to use System.Drawing.Graphics to create object from hWnd, and then get its DC, but it didn't work (it did return something, but OpenGL context didn't setup with that).

Oh, and does Mono work with .Net framework 2.0? Because I'm coding with VS.Net 2005 Beta, and backward-converting the code will just add more trouble (VS.Net 2003 really dislikes when I use unsigned integers).
Mono supports most all of the 2.0 features like generic and anonymous methods. Check out the C# compiler page for a complete list.

For the GetDC API question, look into the Control.CreateGraphics() method. You get the Graphics object automatically in the Paint event handler of a Windows Form.
I was talking about VB.Net compiled using Visual Studio, not Mono compiler. Their VB compiler is not complete yet. I was talking about that if I compiled my project using VB.Net 2005 Beta, and run it on a system with 1.1 .Net framework, it failed displaying a message that it requires 2.0 framework. Strange enough, I don't remember using 2.0-specific features. Will this happen on Mono as well?

And as I said, I already tried to fetch DC through Graphics, and it didn't work. But I'll try again later using CreateGraphics (I did it in another way).

Mono WinForms is now supported on MacOS and X11. Now what is X11? Linux?
Quote:Original post by Seroja
I was talking about VB.Net compiled using Visual Studio, not Mono compiler. Their VB compiler is not complete yet. I was talking about that if I compiled my project using VB.Net 2005 Beta, and run it on a system with 1.1 .Net framework, it failed displaying a message that it requires 2.0 framework. Strange enough, I don't remember using 2.0-specific features. Will this happen on Mono as well?

And as I said, I already tried to fetch DC through Graphics, and it didn't work. But I'll try again later using CreateGraphics (I did it in another way).

Mono WinForms is now supported on MacOS and X11. Now what is X11? Linux?


X11 is the way Linux (as well as some Unixes?) do GUI apps. It's a protocol to connect to an X server (usually XFree86 or X.org), which works with the window manager and GUI apps to make the graphical interface work.

This topic is closed to new replies.

Advertisement