How to disable: Could not register the window class, win32 error 0

I create a DLL with Windows.Forms and add it to Unity pugins directory.

In this dll i open a simple Window and create Windows.Forms components …
Yes, i required these dll, and require windows forms :slight_smile:

The frist time when i call the Windows.Forms.Form f = new Windows.Forms.Form(); no error, all ok
i close the window and open it again i get these error message twice: Could not register the window class, win32 error 0

But the form is open and all work correctly!

What is the problem or what is the workaround?

I make a simple app to solve this problem (i don’t know why can’t by Unity Dev team …)

So, make a small app, when search and close the error window:

        [DllImport( "user32.dll" )]
        public static extern IntPtr FindWindow( string lpClassName, string lpWindowName );
        [DllImport( "user32.dll" )]
        public static extern int SendMessage( IntPtr hWnd, uint Msg, int wParam, int lParam );

        public const int WM_SYSCOMMAND = 0x0112;
        public const int SC_CLOSE      = 0xF060;

        public static void FindAndCloseWindow()
        {
            IntPtr lHwnd = FindWindow( null, "Oops" );
            if ( lHwnd != IntPtr.Zero )
            {
                SendMessage( lHwnd, WM_SYSCOMMAND, SC_CLOSE, 0 );
            }
        }

It just happened to me too.

I think the error occurs when you rebuild the dll on Visual Studio, and go back to Unity, and try to call the dll function before newly built dll is fully reloaded.

You can rebuild the dll, then give a Unity a time to reload it will fix the problem.
If that doesn’t fix the error, restart Unity.