Microsoft DirectX 9.0

Step 1: Create the Windows Framework

Start by creating the basic framework of a Windows application, including WinMain and a window procedure. The WinMain function is not shown here; call CoInitialize before the message loop to initialize the COM library, and CoUninitialize after the message loop exits. Start with the following minimal window procedure:

LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
    static BITMAPINFOHEADER *pbmi = NULL;
    static BYTE *pBuffer = NULL;
    switch (msg)
    case WM_CLOSE:
    case WM_DESTROY:
        if (pbmi) delete [] pbmi;
        return DefWindowProc(hwnd, msg, wparam, lparam);
    return 0;

When you retrieve a poster frame from the Media Detector, it returns a buffer that contains a BITMAPINFOHEADER structure followed by the image bits. Therefore, define two static variables in the window procedure: pbmi will hold a pointer to the BITMAPINFOHEADER structure, and pBuffer will hold a pointer to the bitmap. The application will allocate the buffer in pbmi using new, so it must delete the buffer before the window is destroyed. The pBuffer pointer is calculated as an offset from pbmi, so there is no need to delete it.