[cairo] Cario in Visual Basic

Daniel Amelang daniel.amelang at gmail.com
Mon Feb 12 22:42:12 PST 2007


On 12/18/06, Tor Lillqvist <tml at iki.fi> wrote:
> Jelmer Baas writes:
>  > Private Declare Function cairo_version Lib "libcairo-2.dll" () As String
>  > Private Declare Function cairo_version_string Lib "libcairo-2.dll" () As String
>
>  > Msgbox cairo_version
>  > Msgbox cairo_version_string
>
>  > No matter which one I call, VB6 crashes.
>
> Doesn't VB by default (always?) call functions in DLLs using the
> "stdcall" calling convention? The libcairo-2.dll DLL uses the "cdecl"
> calling convention. You need to write glue code in C to put
> inbetween. (Or, if possible, tell VB that the functions use cdecl.)

For the record: A while back I compiled cairo with the MSVC++ /Gz
option and successfully produced a stdcall cairo dll that Jelmer was
able to call from VB.

The long version of the story is that had to compile static libraries
of zlib and libpng that used the stdcall convention, then add __cdecl
to a couple callback functions in cairo, compile with /Gz and then
statically link it all together, including the C runtime (I changed
all the makefiles throughout to use the /MT flag). The C runtime
needed to be statically linked in because I was using the free VC++
Express which uses the SxS approach for linking in the 8.0 version of
the runtime, which seemed not to be compatible with older versions of
VB when loading a DLL. What a pain.

But, I have to say it was fun to see cairo drawing all over an Excel
spreadsheet. :)

Dan


More information about the cairo mailing list