[.net] VB.Net and cross-platformness

Started by
15 comments, last by nagromo 18 years, 11 months ago
I don't really understand how this works, so could you please answer a few questions: 1) Linux users somehow run Windows programs. Can they also run .Net programs? Do they use Mono? 2) What is Mono? .Net framework for different systems, something like VM for Java, but for .Net, or a .Net cross-platform compiler? 3) What I should/should not use in my VB.Net program to make it at least potentially cross-platform? Thanks in advance!
Advertisement
Quote:Original post by Seroja
1) Linux users somehow run Windows programs. Can they also run .Net programs? Do they use Mono?

To run normal windows programs they typically use WINE. Running .NET programs is actually done totally differently (and is somewhat easier as well). You're right in that Mono is used to run .NET programs under Linux.

Quote:2) What is Mono? .Net framework for different systems, something like VM for Java, but for .Net, or a .Net cross-platform compiler?

Basically, yes. It includes an implementation of the Common Language Runtime (CLR, the virtual machine like thing that .NET programs run under), but also includes a large portion of the .NET Framework (the libraries), a number of extra libraries that aren't part of the .NET Framework, and a C# compiler. I also remember hearing mention of a VB.Net compiler.

Quote:3) What I should/should not use in my VB.Net program to make it at least potentially cross-platform?

Probably the main thing to avoid (and the most annoying) is WinForms. Last I heard very little of this had been implemented, and certainly wasn't particularly useful. There are alternatives though, for example GTK#. GTK+ is a cross-platform GUI library, and GTK# is a set of .NET binding for it (in other words, a .NET library that lets you use the non-.NET GTK+). You should also avoid using P/Invoke directly, as this is used to call OS-specific libraries.

Something probably also worth mentioning, you usually only need to compile your program once. For example, if you compile a cross-platform C# program under Visual Studio, it should run fine under any other .NET implementation without being recompiled (assuming all the required libraries are available)
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Thanks for the answers! I have a few follow-up questions:

1) Is WinForms the regular forms that are used in VB.Net designer? I mean, it opens up with a frm where you can place and position controls. If so, how are the alternatives (GTK#) used in VB? Because I'm used to working with forms visually, and have events in code, not the C-style callback.

2) I use OpenGL from VB.Net - just API calls, no frameworks. So, here are examples of a few functions I need:

Public Declare Function ChoosePixelFormat Lib "gdi32.dll" (ByVal hdc As Integer, ByRef ppfd As PIXELFORMATDESCRIPTOR) As Integer

Public Declare Function wglCreateContext Lib "opengl32.dll" (ByVal hdc As Integer) As Integer

Public Declare Function GetDC Lib "user32.dll" (ByVal hWnd As Integer) As Integer

Public Declare Function GetTickCount Lib "kernel32.dll" () As UInteger

Public Declare Sub glClear Lib "opengl32.dll" (ByVal mask As UInteger)

How should I declare those if I want it cross-platform?

3) What is P/Invoke?

4) I use System.Runtime.InteropServices.Marshal namespace. Will there be any problems about it?

5) I've heard about embedding mono - e.g. making it so that the program will run without mono installed. Is it possible in VB.Net, or do I have to use mono's VB compiler? And will it work on Windows as well, so I can run my program without .Net framework installed?

6) How do I determine what OS am I running under?

Thanks again.
1)Yes. I know work is underway for a Windows.Forms implementation on mono, but I haven't really done anything significant there. You should probably stroll on over go-mono.com

2)You should look into the tao framework, as its cross platform. It also happens to be part of mono now.

3)Platform Invoke - Let's you use native dll's in managed code.

4)Kind of required for the above.

5)Dunno.

6)System.Environment.OSVersion
-----------------------------www.devcrunch.com - independant developer forums
Thanks, but I don't want to use any frameworks. The whole point was using OpenGL in pure VB, and the frameworks are written in C#. So I converted C headers to VB. It works fine, but I wonder what should I change to make it cross platform. Probably OpenGL DLL on Linux/MacOS is not opengl32.dll, but how can I make multiple declares, depending on system? Will it require me to recompile the program for each platform?

BTW, Marshal is not yet available :(

Edit: Just found out that cross-platform Tao supports WGL. How can that be possible? On Linux, GLX is supposed to be used instead, isn't it?
I'll only touch on what POedBoy didn't

Quote:5) I've heard about embedding mono - e.g. making it so that the program will run without mono installed. Is it possible in VB.Net, or do I have to use mono's VB compiler? And will it work on Windows as well, so I can run my program without .Net framework installed?


I imagine you'll have to use Mono's compiler. Mono isn't Linux only, you can use it in Windows instead of Microsoft's .NET implementation, so I imagine if you can do it in Linux then you can do it in Windows. There should be details on the Mono website.

Quote:Thanks, but I don't want to use any frameworks. The whole point was using OpenGL in pure VB, and the frameworks are written in C#.

The beauty of .NET is that language doesn't matter. You can use C# libraries in a VB.Net program or VB.Net libraries in a C# program.

Quote:It works fine, but I wonder what should I change to make it cross platform.

Rewrite Tao [smile]......and I'm actually serious. As far as OpenGL is concerned, Tao is just a wrapper which does exactly the same thing as what you'd end up writing yourself.

Quote:Probably OpenGL DLL on Linux/MacOS is not opengl32.dll, but how can I make multiple declares, depending on system? Will it require me to recompile the program for each platform?

If you really want to know how it's done, check out the Tao source. Sure it's in C#, but so long as you can read C# you can do the same things in VB.Net. Yes, you'd need to recompile since at the very least the dynamic library names are different.

Quote:Just found out that cross-platform Tao supports WGL. How can that be possible? On Linux, GLX is supposed to be used instead, isn't it?

You're correct. What you do is check which OS you're running under and use the appropriate functions. If you use the wrong one you'll get a runtime error saying that the library cannot be found, but it means you don't have to recompile.
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Well I am trying to rewrite Tao in VB :-) Only that I don't make it as a framework, just a few modules with lots of declares, so I call the functions directly.

In Tao they DLLImported all the functions. They just used different libraries for different systems.

Well, up to now my program is not cross-platform :-(
Hopefully they'll finish with WinForms and Marshal when I'm done :-)
Quote:Original post by Seroja
Well I am trying to rewrite Tao in VB :-) Only that I don't make it as a framework, just a few modules with lots of declares, so I call the functions directly.

Why though!? Someone else has already done it for you! (and btw, yours being in VB makes ABSOLUTELY NO DIFFERENCE)

Quote:In Tao they DLLImported all the functions. They just used different libraries for different systems.

Which is exactly what you'll end up doing. Correct?

Quote:Well, up to now my program is not cross-platform :-(
Hopefully they'll finish with WinForms and Marshal when I'm done :-)

Not likely. These expose too much of the underlying operating system (yes, even WinForms does) and would be a serious pain in the **** to implement, and very difficult to justify the time spent (especially since WinForms will be replaced by Avalon soon-ish).
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Yes - you can run .NET programs under Mono, but there are certain things which will never work:

P/Invoke into win32 DLLs - is clearly not going to work on Mono on non-win32 platforms.

(P/Invoke into platform-independent DLLs might conceivably work though)

OpenGL itself is no different, but creating contexts is.

I can't see the wgl functions *ever* being available under (for example) Linux - which of course has its own set of functions for setting up contexts etc, the "glx" functions. These are different because they're interfacing into a different underlying window system.

You could conceivably P/Invoke GLFW.dll (if indeed, it is a DLL) and opengl32.dll (libGL.so or whatever on Linux) - but I don't hold my hopes out.

Mark
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).

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.

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?

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?

This topic is closed to new replies.

Advertisement