public static int Run(DXSample pSample, HINSTANCE hInstance, int nCmdShow) { // Parse the command line parameters pSample.ParseCommandLineArgs(Environment.GetCommandLineArgs()); fixed(char *lpszClassName = "DXSampleClass") fixed(char *lpWindowName = pSample.Title) { // Requires an explicit cast until C# handles UnmanagedCallersOnly var wndProc = (delegate * stdcall <IntPtr, uint, nuint, nint, nint>)(delegate * managed <IntPtr, uint, nuint, nint, nint>) & WindowProc; // Initialize the window class. var windowClass = new WNDCLASSEXW { cbSize = (uint)sizeof(WNDCLASSEXW), style = CS_HREDRAW | CS_VREDRAW, lpfnWndProc = wndProc, hInstance = hInstance, hCursor = LoadCursorW(IntPtr.Zero, (ushort *)IDC_ARROW), lpszClassName = (ushort *)lpszClassName }; _ = RegisterClassExW(&windowClass); var windowRect = new RECT { right = unchecked ((int)pSample.Width), bottom = unchecked ((int)pSample.Height) }; _ = AdjustWindowRect(&windowRect, WS_OVERLAPPEDWINDOW, FALSE); // Create the window and store a handle to it. s_hwnd = CreateWindowExW( 0, windowClass.lpszClassName, (ushort *)lpWindowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, HWND.NULL, // We have no parent window. HMENU.NULL, // We aren't using menus. hInstance, ((IntPtr)GCHandle.Alloc(pSample)).ToPointer() ); } // Initialize the sample. OnInit is defined in each child-implementation of DXSample. pSample.OnInit(); _ = ShowWindow(s_hwnd, nCmdShow); // Main sample loop. MSG msg; do { // Process any messages in the queue. if (PeekMessageW(&msg, IntPtr.Zero, 0, 0, PM_REMOVE) != 0) { _ = TranslateMessage(&msg); _ = DispatchMessageW(&msg); } }while (msg.message != WM_QUIT); pSample.OnDestroy(); // Return this part of the WM_QUIT message to Windows. return((int)msg.wParam); }