Example 2:
Defining an array of pixel objects in the bitmap
Dim pPixels(100) Set pPicture = CreateObject("Picture.Bitmap") pPicture.Width = 100 pPicture.Height = 100 For i = 0 to 99 Set pPixels(i) = CreateObject("Picture.Pixel") pPixels(i).Row = i pPixels(i).Column = i pPixels(i).Color = 2 Next pPicture.SetPoints pPixels STDMETHODIMP CBitmap::SetPoints(VARIANT vPoints) { // Read a set of points defined in vPoints to apply them to // the current picture if (!(vPoints.vt & VT_VARIANT) || !(vPoints.vt & VT_BYREF)) return E_INVALIDARG; // Get the low and upper bound of the array HRESULT hr = S_OK; SAFEARRAY* pArray = *vPoints.pvarVal->pparray; LONG lBound, uBound; if (FAILED(SafeArrayGetLBound(pArray, 1, &lBound)) || FAILED(SafeArrayGetUBound(pArray, 1, &uBound))) return E_INVALIDARG; // And set the point for each pixel of the array for (long iPixel = lBound; iPixel < uBound; iPixel++) { // Get the Pixel object VARIANT vPixel; SafeArrayGetElement(pArray, &iPixel, &vPixel); // Set the point by forwarding the object to SetPoint if (vPixel.vt == VT_DISPATCH || vPixel.vt == VT_UNKNOWN) { CComQIPtr<IPixel> pPixel = vPixel.pdispVal; if (pPixel.p && FAILED(hr = SetPoint(pPixel))) break; } } return hr; }