public WindowManager(
            [Import] Lazy <IDispatchManager> dispatchManager
            )
        {
            _lpClassName     = (WCHAR *)(Marshal.StringToHGlobalUni($"TerraFX.Interop.Provider.Win32.UI.Window.{EntryModuleHandle}"));
            _lpWindowName    = (WCHAR *)(Marshal.StringToHGlobalUni($"TerraFX Win32 Window"));
            _dispatchManager = dispatchManager;

            var wndClassEx = new WNDCLASSEX()
            {
                cbSize        = unchecked ((uint)(Marshal.SizeOf <WNDCLASSEX>())),
                style         = CS.VREDRAW | CS.HREDRAW,
                lpfnWndProc   = WndProc,
                cbClsExtra    = 0,
                cbWndExtra    = 0,
                hInstance     = EntryModuleHandle,
                hIcon         = HICON.NULL,
                hCursor       = HCURSOR.NULL,
                hbrBackground = (IntPtr)(COLOR.WINDOW + 1),
                lpszMenuName  = LPWSTR.NULL,
                lpszClassName = _lpClassName,
                hIconSm       = HICON.NULL
            };

            var classAtom = RegisterClassEx(ref wndClassEx);

            if (classAtom == 0)
            {
                ExceptionUtilities.ThrowExternalExceptionForLastError(nameof(RegisterClassEx));
            }

            _classAtom = classAtom;
        }
        private void Dispose(bool isDisposing)
        {
            if (isDisposing)
            {
                foreach (var createdWindow in CreatedWindows.Values)
                {
                    createdWindow.Dispose();
                }
            }

            if (_classAtom != 0)
            {
                var lpClassName = (LPWSTR)(_classAtom);
                UnregisterClass(lpClassName, EntryModuleHandle);
                _classAtom = 0;
            }

            if (_lpWindowName != null)
            {
                Marshal.FreeHGlobal((IntPtr)(_lpWindowName));
                _lpWindowName = null;
            }

            if (_lpClassName != null)
            {
                Marshal.FreeHGlobal((IntPtr)(_lpClassName));
                _lpClassName = null;
            }
        }
Beispiel #3
0
 /// <summary>Initializes a new instance of the <see cref="LPWSTR" /> struct.</summary>
 /// <param name="value">The value of the instance.</param>
 public LPWSTR(WCHAR *value)
 {
     _value = value;
 }