GMP under VB6
mathimagics at yahoo.co.uk
Wed Aug 8 14:14:32 CEST 2007
> Date: Mon, 6 Aug 2007 18:33:51 +0200
> From: "Klaus Reimann" <klaus.reimann at gmx.de>
> I want to use the GMP long Interger arithmetic
> in a VB6 application and only need the *.dll s
> as I am not a c programmer, I dont know
You do need to know one very important thing about C -
dll's built with default C settings can NOT be called
directly from VB6.
This is due to a fundamental difference in the
language specification. Unlike most standard languages
that existed before it (and most languages invented
after it, too) C programs at runtime use an
argument-passing convention, called "cdecl", that
renders C libraries incompatible with most non-C
callers, who use the traditional calling convention,
Most C compilers for Windows necessarily support both
modes, but it is up to the builder of the library to
make specific settings that will allow the resulting
DLL to be called by other languages.
You can call Windows API functions from VB6 only
because the entire Windows API is specifically built
to make 99% of API functions stdcall-compatible.
In theory, GMP dll's could be built differently to
export stdcall entrypoints, but for various reasons
that is a painful exercise.
You can call cdecl DLL's, and this includes Rob's
excellent set of GMP DLL's, from VB6, but you need a
One way is to make a separate DLL which provides the
required stdcall entrypoints, and which simply
delegates (passes on) those calls on to the real GMP
Ironically, VB6 has an undocumented feature - a VB6
program CAN in fact call a cdecl DLL - but ONLY when
it's run as an EXE - you will crash the IDE if you
execute the same code from there.
Which explains why it remains undocumented ....
I tell you all this because it's worth recording here
a reasonably detailed description of this particular
The good news is that a delegator DLL for GMP will
shortly be available, I'm just in the process of
tidying it up and making it as seamless as possible.
I will advise details and where to download it from as
soon as I can - hopefully within the next 7 days.
More information about the gmp-discuss