VB6/GMP via PowerBasic Wrapper DLL
Jim White
mathimagics at yahoo.co.uk
Tue Jul 4 14:14:28 CEST 2006
> we could call deltatrinity's "ready-rolled" Win32
> GMP DLL's by using a "wrapper DLL" written in
> PowerBasic he gave an example:
> TYPE MPF
> mp_prec AS LONG
> mp_size AS LONG
> mp_expt AS LONG
> mp_limb AS LONG
> END TYPE
>
> DECLARE SUB cMPFinit CDECL LIB
> "libgmp-3.dll" ALIAS "__gmpf_init" (X
> AS MPF)
>
> DECLARE SUB cMPFclear CDECL LIB "libgmp-3.dll"
> ALIAS "__gmpf_clear" (X
> AS MPF)
>
> SUB MPFinit(x AS MPF) EXPORT
> CALL cMPFinit(x)
> END SUB
>
> SUB MPFclear(x AS MPF) EXPORT
> CALL cMPFclear(x)
> END SUB
> i have made the above dll using powerbasic and put
> it in a directory with libgmp-3.dll and libgmp-3.lib
> but VB6 can't add a reference to this dll.
Hi Peter
1. "VB6 can't add a reference"
When making API calls (ie: calls to DLL functions
declared with VB6 "Declare"), you do NOT try to get
VB6 to add a reference to that DLL. The "DLL
reference" mechanism is for importing Type Libraries,
and has nothing to do with the GMP interface.
2. Before I give the correct VB6 syntax, I should
point out that by default PB exports functions by
their declared name mapped to UpperCase. So the
sample above would export its functions as MPFCLEAR
and MPFINIT. You can specify a case-sensitive name of
your choosing with the ALIAS clause (ie: ALIAS can
specify import names and also export names).
Say you wanted to use the standard GMP function names
in your VB6 client (which is a good idea in general).
The PB code would look like this:
SUB MPFinit Alias "mpf_init" (x AS MPF) EXPORT
CALL cMPFinit(x)
END SUB
SUB MPFclear Alias "mpf_clear" (x AS MPF) EXPORT
CALL cMPFclear(x)
END SUB
Assuming your VB6 client declares the MPF type exactly
as above in the PB sample code, then, if the PB dll
name is "pbgmp.dll", say, the VB6 client declares the
functions like this:
Declare Sub mpf_init lib "pbgmp.dll" (X As MPF)
Declare Sub mpf_clear lib "pbgmp.dll" (X As MPF)
Since I have used the exact names here that I used in
the PB dll's ALIAS clauses, I don't need to use
"Alias" in the VB6 code.
Alternatively, the PB DLL compiled without ALIAS
clauses could be called from VB6 with these
declarations. As I said, if PB doesn't see an ALIAS
clause it will export the function as UCASE(declared
name):
Declare Sub mpf_init Alias "MPFINIT" _
lib "pbgmp.dll" (X As MPF)
Declare Sub mpf_clear Alias "MPFCLEAR" _
lib "pbgmp.dll" (X As MPF)
Cheers
Jim White
ANU
More information about the gmp-discuss
mailing list