When use Cairo (​​http://cairographics.org/​​ ), you may meet the nasty question: "First-chance exception at 0x68e629dc in test.exe: 0xC0000005: Access violation reading location 0xabababa7". This error message only occurs when the app  is on exit.

 

What's First-chance exception in Cairo on exit? and does it matter? See these discusses:

​http://stackoverflow.com/questions/3610888/cairo-error-message-on-exit​

 

and

 

​http://blogs.msdn.com/b/davidklinems/archive/2005/07/18/440150.aspx​

 

In general, it is harmless. so don't warry about that and feel at ease to use cairo.

 

Sample code bellow:

 

CChildView::CChildView()
{
testsurface = cairo_image_surface_create_from_png("BlackShinyBackground.png");
}
CChildView::~CChildView()
{
cairo_surface_destroy(testsurface);
}
void CChildView::OnPaint()
{
CPaintDC dc(this);
cairo_surface_t *surface = cairo_win32_surface_create(dc.m_hDC);
cairo_t *cr = cairo_create (surface);
cairo_set_source_surface(cr, testsurface, 0, 0);
cairo_paint(cr);
cairo_destroy (cr);
cairo_surface_destroy (surface);
}

 

or another one:

 

// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// Use cario
#include "../include/cairo/cairo-win32.h" // exam_draw_img
#include "../include/cairo/cairo-pdf.h" // exam_draw_pdf
#include "../include/cairo/cairo-svg.h" // exam_draw_svg
#pragma comment(lib, "../lib/cairo.lib")
void exam_draw_png()
{
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 640, 480);
cr = cairo_create (surface);
cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 100.0, 100.0);
cairo_show_text (cr, "This is an Example using PNG as drawing output!");

cairo_rectangle(cr,10,10,100,100);
cairo_set_line_width(cr,10);
cairo_set_source_rgb(cr,0,0,1);
cairo_stroke(cr);
cairo_move_to(cr,0,0);
cairo_line_to(cr,100,100);
cairo_set_source_rgb(cr,1,0,0);
cairo_stroke(cr);
cairo_surface_write_to_png (surface, "c://exam_draw_png.png");

cairo_destroy (cr);
cairo_surface_destroy (surface);
}
void exam_draw_pdf()
{
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_pdf_surface_create ("c://exam_draw_pdf.pdf", 640, 480);
cr = cairo_create (surface);
cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 100, 100);
cairo_show_text (cr, "This is an Example using PDF as drawing output!");
cairo_rectangle(cr,10,10,100,100);
cairo_set_line_width(cr,10);
cairo_set_source_rgb(cr,0,0,1);
cairo_stroke(cr);
cairo_move_to(cr,0,0);
cairo_line_to(cr,100,100);
cairo_set_source_rgb(cr,1,0,0);
cairo_stroke(cr);
cairo_show_page (cr);
cairo_destroy (cr);
cairo_surface_destroy (surface);
}
void exam_draw_svg()
{
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_svg_surface_create ("c://exam_draw_svg.svg", 320, 48);
cr = cairo_create (surface);
cairo_set_source_rgb (cr, 0.627, 0, 0);
cairo_select_font_face (cr, "serif",
CAIRO_FONT_SLANT_NORMAL,
CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, 24.0);
cairo_move_to (cr, 10.0, 34.0);
cairo_show_text (cr, "This is an Example using SVG as drawing output!");
cairo_destroy (cr);
cairo_surface_destroy (surface);
}
int _tmain(int argc, _TCHAR* argv[])
{
exam_draw_png();
exam_draw_svg();
exam_draw_pdf();
return 0;
}