VB6/GMP via PowerBasic Wrapper DLL

Jim White mathimagics at yahoo.co.uk
Fri Jul 7 03:45:02 CEST 2006


> mpf_init (n)

In VB6, you should use either of the following forms:

         Call mpf_init(n)

         mpf_init n

If you omit the Call keyword, you don't parenthesise
the argument list.  If you do parenthesise, VB then
assumes you want that expression evaluated, hence the
error message.

> i have looked at a code in the PurBasic
> forum:
>
http://www.purebasic.fr/english/viewtopic.php?t=10776&start=0&postdays=0&postorder=asc&highlight=&sid=1dc7bfe4a44f32ac9dcfb11f57ab8a80

>   CallFunction(1,"__gmpf_init2",x,256); initialize


I don't know anything about PureBasic, that's a new
one for me, but given the syntax above I can guess
what they are doing.

I have a similar function, in fact, called "CallANY".
It's a generic "call any DLL function without
declaration" service, allowing you to bypass the VB6 
Declare/Call mechanism entirely.

Bear in mind this sort of tweak also bypasses all the
normal error detection and recovery mechanisms you get
when you stick to the standard syntax.

For example, a "CallANY" approach can't give you any
clues at compile time as to whether your target
function name is valid, or if your argument list makes
any sense.  At run-time minor errors can easily result
in crashes.

If you know what you're doing, though, it's a powerful
mechanism, particularly in relation to the generic
STDCALL vs CDECL mechanism.

That's because you can give CallANY a flag at runtime
to tell it to use CDECL (ie. to clean up the stack
after the call).

My recommendation, however, is that compile-time
checking is still worth retaining, and the PowerBasic
wrapper DLL remains the best solution, IMHO.

I can provide you with my current PowerBasic DLL,
which already has a good range of ready-to-use GMP mpz
and mpf functions (and is easily extended). I can also
give you the coresponding VB6 include file (with the
DECLARE's).


Another advantage of this approach is that you can use
the PowerBasic dll to modify the calling interface, or
provide intermediate-level functions.

I can also provide a copy of my CallANY DLL (it's
written in MASM) if you still want to try that
approach.

Cheers

Jim White
ANU, Canberra



More information about the gmp-discuss mailing list