0

I have been trying for a while to get this fixed but I haven't seen any solutions online on this topic yet.

The problem is when using MonoGame with the Platform DesktopGL, the Window.Handle seems invalid. As attempting to get a Window/Form from this Handle returns null, further supporting this would be BASS.Net Not being able to play audio on this Window Handle,

Here's part of my code that's attempting to use the Handle (Uses Bass.Net for Audio Playback):

protected override void Initialize() {
    Game = this;

    //Getting the Form from Window Handle
    Form = (Form)Control.FromHandle(Game.Window.Handle);

    //Initializing Bass with Window Handle
    Bass.BASS_Init(-1, 4100, BASSInit.BASS_DEVICE_DEFAULT, Game.Window.Handle, null);

    base.Initlialize()
}

I have tried to look everywhere online, 1 source stating that the MonoGame platform WindowsDX apperantly returns a valid Form, though from what ive noticed in the never versions of MonoGame this platform doesn't seem to be supported anymore, furthermore I would love to have this Project be Cross-Platform so sticking with WindowsDX even if it were to exist/work wouldn't be a good solution I think.

Thanks In advance to anyone who manages to find as to why MonoGame doesn't return me a Window and or why this Particular Piece of code doesn't work.

  • Checking the online documentation for MonoGame shows that `Game.Window` returns a `GameWindow` instance ([source](https://docs.monogame.net/api/Microsoft.Xna.Framework.Game.html#Microsoft_Xna_Framework_Game_Window)) and its `Handle` property returns a `IntPtr` ([source](https://docs.monogame.net/api/Microsoft.Xna.Framework.GameWindow.html#Microsoft_Xna_Framework_GameWindow_Handle)). Which you can't directly cast to a `Form`, you could use `Control.FromHandle` and cast to a `Form`, but I'm not sure if MonoGame's Window is based on WinForms' `Form` class – MindSwipe Apr 26 '21 at 07:57
  • Older Versions of XNA (which is what the old project I'm porting over to MonoGame used) also had Game.Window be a GameWindow instance, and it indeed was able to return a Form from it's handle, so I'm not entirely sure anymore. – Arkadiusz Brzoza Apr 26 '21 at 08:03
  • You said " furthermore I would love to have this Project be Cross-Platform", but if you are relying on Form (and Winforms) then it is already not cross platform. I'm not familiar with Bass, but if it relies on a Windows Form to initialize, then it is also not cross-platform. – Victor Chelaru Apr 28 '21 at 22:40

1 Answers1

1

"Window.Handle" is only valid on WindowsDX platform.

OpenGL, no matter the platform(including Windows), can satisfy this request.

If you are looking for a cross platform solution, look elsewhere.