LISTING 1

int SomeFunc () {
	ISomeInterface *ip = CreateSomeInterface ();
	if (ip == NULL)
		return -1;

	HRESULT hr;
	int num = 0;
	hr = ip->GetCount (&num);
	if (SUCCEEDED (hr)) {	
		for (int i = 0; i < num; i++) {
			hr = ip->FirstFunc (i);
			if (FAILED (hr)) {
				ip->Release ();
				return -2;
			}
			hr = ip->SecondFunc (i);
			if (FAILED (hr)) {
				ip->Release ();
				return -3;
			}
		}
	} else {
		ip->Release ();
		return -4;
	}
	ip->Release ();
	return 0;
}

LISTING 2:

private void LoadImage_Click(object sender, 
	System.EventArgs e) {
	try {
		Bitmap b = new Bitmap (ImageFileName.Text);
		ImageControl.Image = b;
	} catch (Exception ex) {
		string s = "Error: " + ex.Message;
		System.Windows.Forms.MessageBox.Show(s, 
			"Image Viewer");
	} finally {
		this.panel2.Size = this.ImageControl.Size;
		UpdateInfo ();
	}
}

private void Browse_Click(object sender, 
	System.EventArgs e) {
	// Open a browse dialog and get a file name.
	OpenFileDialog d = new OpenFileDialog ();
	d.FileName=ImageFileName.Text;
	DialogResult r  = d.ShowDialog();
	if (r == DialogResult.OK) {
		// Set the image text property:
		ImageFileName.Text = d.FileName;
		// Reset the image:
		ImageControl.Image=null;
		using (System.IO.Stream s = 
			d.OpenFile()){
			Bitmap b = new Bitmap(s);
			ImageControl.Image = b;
	this.panel2.Size = 
		this.ImageControl.Size;
		}
		UpdateInfo ();
	}
}
