www.digitalmars.com         C & C++   DMDScript  

D - imagemagick wrapper?

reply "Mårten Ask" <majbritt37 hotmail.com> writes:
Hi,

I want to use som functions from the imagemagick C api. How do I do that?
How do I call the functions and objects and how do I link with the dll's?
Aug 12 2003
parent reply "Mike Wynn" <mike.wynn l8night.co.uk> writes:
here's a templated class lib I wrote to help with dll loading ('cos I like
the delphi extern "foo.dll"; )
and an example (loads winmm.dll to all access to multimedia timers)
due to D's templateing its a little verbose, but works ...

first make instances of the types of functions you want to import
e.g. `extern (windows) DWORD func();`
instance DynFunc( Windows, DWORD ) noParamReturnsDword;

the declare a func pointer to it (using the template instance)
`<instance>.fp` e.g. ....
noParamReturnsDword.fp myFunc;

// now write a static initialiser to your module to load the dll and get the
function.
// there are two ways to do this both have the same result but its personal
preference which you use
static this()
{
// fp = <template>.require( <dll name>, <func_name> ); // I perfer this
myFunc = I_I_Ldr.require( "foo.dll", "someFuncname" );
// <template>.use( fp, <dll name>, <func_name> );
noParamReturnsDword.use( myFunc,   "foo.dll", "someFuncname" );
}

for C fucntions use
instance DynFunc( C, <return_type>, <param1>, <param2> .... ) somename;
if the return type is void due to D templates you can't use
instance DynFunc( C, void, int );
instead you have to use DynProc( C, int );
or DyncProc( C ) => extern(C) void func( void );

to do it manually here the code that loads up and gets a directx d3d
interface from the function
`Direct3DCreate8` in `d3d8.dll`

extern(Windows) alias IDirect3D8 function( UINT ) start_up_fp;

IDirect3D8 loadD3DLibs() {
 HMODULE sysModule;
 sysModule = LoadLibraryA( "d3d8.dll" );   // load a dll
 FARPROC fp = GetProcAddress( sysModule, cast(char*)"Direct3DCreate8" ); //
get a function pointer
 assert(fp);
 start_up_fp dxfp = cast(start_up_fp)fp;
 return dxfp(D3D_SDK_VERSION);
}

failing all that .... use implib to convert the dll to a .lib and just write
the functions as
extern( C ) .....
or extern(Windows) .....
the linker will the link correctly against <foo>.dll if you link against the
created lib file.


"Mårten Ask" <majbritt37 hotmail.com> wrote in message
news:bhb9cs$1eq3$1 digitaldaemon.com...
 Hi,

 I want to use som functions from the imagemagick C api. How do I do that?
 How do I call the functions and objects and how do I link with the dll's?
begin 666 dynloader.d M;6]D=6QE('=I;F5X+F1Y;FQO861E<CL-"FEM<&]R="!W:6YD;W=S.PT*#0IE M;G5M($QI;FMA9V4 >R!7:6YD;W=S+"!#+"!$('T-"F%L:6%S($QI;FMA9V4N M5VEN9&]W<R!7:6YD;W=S.PT*86QI87, 3&EN:V%G92Y#($,[#0IA;&EA<R!, M:6YK86=E+D0 1#L-" T*8VQA<W, 4VAA<F5D3&EB<F%R>2![#0H)<')I=F%T M92!(34]$54Q%('-Y<TUO9'5L93L-" EP<F]T96-T960 =&AI<R 8VAA<EM= M('!A=& *2![#0H)"7-Y<TUO9'5L92 ]($QO861,:6)R87)Y02 <&%T:" I M.PT*"0EI9B H("%S>7--;V1U;&4 *2!T:')O=R!N97< 17AC97!T:6]N*" B M=6YA8FQE('1O(&QO860 <VAA<F5D(&QI8G)A<GD (B!^('!A=& *3L-" E] M#0H)<'5B;&EC($9!4E!23T, 9V5T1G5N8W1I;VY!9&1R97-S*"!C:&%R6UT M9G5N8TYA;64 *0T*"7L-" D)1D%24%)/0R!F<" ]($=E=%!R;V-!9&1R97-S M*"!S>7--;V1U;&4L(&-A<W0H8VAA<BHI9G5N8TYA;64 *3L-" D):68 *" A M9G *2!T:')O=R!N97< 17AC97!T:6]N*" B=6YA8FQE('1O(&=E="!F=6YC M(&%D9')E<W, (B!^(&9U;F-.86UE("D[#0H)"7)E='5R;B!F<#L-" E]#0H) M<')I=F%T92!S=&%T:6, 4VAA<F5D3&EB<F%R>5MC:&%R6UU=(&QO861E9#L- M" EP=6)L:6, <W1A=&EC(%-H87)E9$QI8G)A<GD ;&]A9$QI8G)A<GDH(&-H M87);72!P871H("D-" E[#0H)"5-H87)E9$QI8G)A<GD <VP[#0H)"6EF(" M*'-L(#T ;&]A9&5D6W!A=&A=*2 ]/3T ;G5L;" I(')E='5R;B!L;V%D961; M<&%T:%T /2!N97< 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I;FMA9V4 5" Z($QI;FMA9V4N0R I('L- M" EE>'1E<FX *$,I('L #0H)"79O:60 97)F*"D >R!T:')O=R!N97< 17AC M97!T:6]N*" B4VAA<F5D($9U;F-T:6]N(&YO="!L;V%D960B("D[('T #0H) M"71Y<&5D968 =F]I9" H*F9P*2 I(#T )F5R9CL-" E]#0H):6YS=&%N8V4 M1'EN*"!F<" I(&1Y;D9U;F,[#0H)86QI87, 9'EN1G5N8RYU<V4 =7-E.PT* M"6%L:6%S(&1Y;D9U;F,N<F5Q=6ER92!R97%U:7)E.PT*?0T*#0IT96UP;&%T M92!$>6Y0<F]C*"!,:6YK86=E(%0 .B!,:6YK86=E+D0L(% *2![#0H)=F]I M9"!E<F8H(% <" I('L =&AR;W< ;F5W($5X8V5P=&EO;B (E-H87)E9"!& M=6YC=&EO;B!N;W0 ;&]A9&5D(B I.R!]( T*"71Y<&5D968 =F]I9" H*F9P M*2 4" I(#T )F5R9CL-" EI;G-T86YC92!$>6XH(&9P("D 9'EN1G5N8SL- M" EA;&EA<R!D>6Y&=6YC+G5S92!U<V4[#0H)86QI87, 9'EN1G5N8RYR97%U M:7)E(')E<75I<F4[#0I]#0IT96UP;&%T92!$>6Y0<F]C*"!,:6YK86=E(%0 M.B!,:6YK86=E+E=I;F1O=W,L(% *2![#0H)97AT97)N("A7:6YD;W=S*2![ M#0H)"79O:60 97)F*"!0(' *2![('1H<F]W(&YE=R!%>&-E<'1I;VXH(")3 M:&%R960 1G5N8W1I;VX ;F]T(&QO861E9"( *3L ?2 -" D)='EP961E9B!V M;VED(" J9G I*"!0("D /2 F97)F.PT*"7T-" EI;G-T86YC92!$>6XH(&9P M("D 9'EN1G5N8SL-" EA;&EA<R!D>6Y&=6YC+G5S92!U<V4[#0H)86QI87, M9'EN1G5N8RYR97%U:7)E(')E<75I<F4[#0I]#0IT96UP;&%T92!$>6Y0<F]C M*"!,:6YK86=E(%0 .B!,:6YK86=E+D,L(% *2![#0H)97AT97)N(" 0R I M('L-" D)=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96UP;&%T92!$>6Y0<F]C*"!,:6YK86=E(%0 .B!,:6YK86=E M+D,L(% P+"!0,2 I('L-" EE>'1E<FX *"!#("D >PT*"0EV;VED(&5R9B M4# <# L(% Q(' Q("D >R!T:')O=R!N97< 17AC97!T:6]N*" B4VAA<F5D M($9U;F-T:6]N(&YO="!L;V%D960B("D[(')E='5R;B!2+FEN:70[('T #0H) M"71Y<&5D968 =F]I9" H*F9P*2 4# L(% Q("D /2 F97)F.PT*"7T-" EI M;G-T86YC92!$>6XH(&9P("D 9'EN1G5N8SL-" EA;&EA<R!D>6Y&=6YC+G5S M92!U<V4[#0H)86QI87, 9'EN1G5N8RYR97%U:7)E(')E<75I<F4[#0I]#0H- M" T*=&5M<&QA=&4 1'EN1G5N8R 3&EN:V%G92!4("D >PT*"6EN<W1A;F-E M($1Y;E!R;V,H(%0 *2!R96%L5&5M<&QA=&4[#0H)86QI87, <F5A;%1E;7!L M871E+F5R9B!E<F8[#0H)86QI87, <F5A;%1E;7!L871E+F9P(&9P.PT*"6%L M:6%S(')E86Q496UP;&%T92YU<V4 =7-E.PT*"6%L:6%S(')E86Q496UP;&%T M92YR97%U:7)E(')E<75I<F4[#0I]#0H-"G1E;7!L871E($1Y;D9U;F,H($QI M;FMA9V4 5"P 4B Z('9O:60 *2![#0H):6YS=&%N8V4 1'EN4')O8R 5" I M(')E86Q496UP;&%T93L-" EA;&EA<R!R96%L5&5M<&QA=&4N97)F(&5R9CL- M" EA;&EA<R!R96%L5&5M<&QA=&4N9G 9G [#0H)86QI87, <F5A;%1E;7!L M871E+G5S92!U<V4[#0H)86QI87, <F5A;%1E;7!L871E+G)E<75I<F4 <F5Q M=6ER93L-"GT-" T*=&5M<&QA=&4 1'EN1G5N8R 3&EN:V%G92!4(#H 3&EN M:V%G92Y$+"!2("D >PT*"5( 97)F*"D >R!T:')O=R!N97< 17AC97!T:6]N M*" B4VAA<F5D($9U;F-T:6]N(&YO="!L;V%D960B("D[(')E='5R;B!2+FEN M:70[('T #0H)='EP961E9B!2(" J9G I*"D /2 F97)F.PT*"6EN<W1A;F-E M($1Y;B 9G *2!D>6Y&=6YC.PT*"6%L:6%S(&1Y;D9U;F,N=7-E('5S93L- M" EA;&EA<R!D>6Y&=6YC+G)E<75I<F4 <F5Q=6ER93L-"GT-" T*=&5M<&QA M=&4 1'EN1G5N8R 3&EN:V%G92!4(#H 3&EN:V%G92Y#+"!2("D >PT*"65X M=&5R;B H($, *2![#0H)"5( 97)F*"D >R!T:')O=R!N97< 17AC97!T:6]N M*" B4VAA<F5D($9U;F-T:6]N(&YO="!L;V%D960B("D[(')E='5R;B!2+FEN M:70[('T #0H)"71Y<&5D968 4B H*F9P*2 I(#T )F5R9CL-" E]#0H):6YS M=&%N8V4 1'EN*"!F<" I(&1Y;D9U;F,[#0H)86QI87, 9'EN1G5N8RYU<V4 M=7-E.PT*"6%L:6%S(&1Y;D9U;F,N<F5Q=6ER92!R97%U:7)E.PT*?0T*#0IT M96UP;&%T92!$>6Y&=6YC*"!,:6YK86=E(%0 .B!,:6YK86=E+E=I;F1O=W,L M(%( *2![#0H)97AT97)N(" 5VEN9&]W<R I('L-" D)4B!E<F8H*2![('1H M<F]W(&YE=R!%>&-E<'1I;VXH(")3:&%R960 1G5N8W1I;VX ;F]T(&QO861E M9"( *3L <F5T=7)N(%(N:6YI=#L ?2 -" D)='EP961E9B!2(" J9G I*"D M/2 F97)F.PT*"7T-" EI;G-T86YC92!$>6XH(&9P("D 9'EN1G5N8SL-" EA M;&EA<R!D>6Y&=6YC+G5S92!U<V4[#0H)86QI87, 9'EN1G5N8RYR97%U:7)E M(')E<75I<F4[#0I]#0H-"G1E;7!L871E($1Y;D9U;F,H($QI;FMA9V4 5" Z M($QI;FMA9V4N1"P 4B Z('9O:60L(% *2![#0H):6YS=&%N8V4 1'EN4')O M8R 5"P 4" I(')E86Q496UP;&%T93L-" EA;&EA<R!R96%L5&5M<&QA=&4N M97)F(&5R9CL-" EA;&EA<R!R96%L5&5M<&QA=&4N9G 9G [#0H)86QI87, M<F5A;%1E;7!L871E+G5S92!U<V4[#0H)86QI87, <F5A;%1E;7!L871E+G)E M<75I<F4 <F5Q=6ER93L-"GT-" T*=&5M<&QA=&4 1'EN1G5N8R 3&EN:V%G M92!4(#H 3&EN:V%G92Y#+"!2(#H =F]I9"P 4" I('L-" EI;G-T86YC92!$ M>6Y0<F]C*"!4+"!0("D <F5A;%1E;7!L871E.PT*"6%L:6%S(')E86Q496UP M;&%T92YE<F8 97)F.PT*"6%L:6%S(')E86Q496UP;&%T92YF<"!F<#L-" EA M;&EA<R!R96%L5&5M<&QA=&4N=7-E('5S93L-" EA;&EA<R!R96%L5&5M<&QA M=&4N<F5Q=6ER92!R97%U:7)E.PT*?0T*#0IT96UP;&%T92!$>6Y&=6YC*"!, M:6YK86=E(%0 .B!,:6YK86=E+E=I;F1O=W,L(%( .B!V;VED+"!0("D >PT* M"6EN<W1A;F-E($1Y;E!R;V,H(%0L(% *2!R96%L5&5M<&QA=&4[#0H)86QI M87, <F5A;%1E;7!L871E+F5R9B!E<F8[#0H)86QI87, <F5A;%1E;7!L871E M+F9P(&9P.PT*"6%L:6%S(')E86Q496UP;&%T92YU<V4 =7-E.PT*"6%L:6%S M(')E86Q496UP;&%T92YR97%U:7)E(')E<75I<F4[#0I]#0H-"G1E;7!L871E M($1Y;D9U;F,H($QI;FMA9V4 5" Z($QI;FMA9V4N1"P 4BP 4" I('L-" E2 M(&5R9B 4"!P("D >R!T:')O=R!N97< 17AC97!T:6]N*" B4VAA<F5D($9U M;F-T:6]N(&YO="!L;V%D960B("D[(')E='5R;B!2+FEN:70[('T #0H)='EP M961E9B!2(" J9G I*% I(#T )F5R9CL-" EI;G-T86YC92!$>6XH(&9P("D M9'EN1G5N8SL-" EA;&EA<R!D>6Y&=6YC+G5S92!U<V4[#0H)86QI87, 9'EN M1G5N8RYR97%U:7)E(')E<75I<F4[#0I]#0IT96UP;&%T92!$>6Y&=6YC*"!, M:6YK86=E(%0 .B!,:6YK86=E+E=I;F1O=W,L(%(L(% *2![#0H)97AT97)N M(" 5VEN9&]W<R I('L-" D)4B!E<F8H(% <" I('L =&AR;W< ;F5W($5X M8V5P=&EO;B (E-H87)E9"!&=6YC=&EO;B!N;W0 ;&]A9&5D(B I.R!R971U M<FX 4BYI;FET.R!]( T*"0ET>7!E9&5F(%( *"IF<"DH4"D /2 F97)F.PT* M"7T-" EI;G-T86YC92!$>6XH(&9P("D 9'EN1G5N8SL-" EA;&EA<R!D>6Y& M=6YC+G5S92!U<V4[#0H)86QI87, 9'EN1G5N8RYR97%U:7)E(')E<75I<F4[ M#0I]#0IT96UP;&%T92!$>6Y&=6YC*"!,:6YK86=E(%0 .B!,:6YK86=E+D,L M(%(L(% *2![#0H)97AT97)N*"!#("D >PT*"0E2(&5R9B 4"!P("D >R!T M:')O=R!N97< 17AC97!T:6]N*" B4VAA<F5D($9U;F-T:6]N(&YO="!L;V%D M960B("D[(')E='5R;B!2+FEN:70[('T #0H)"71Y<&5D968 4B H*F9P*2A0 M*2 ]("9E<F8[#0H)?0T*"6EN<W1A;F-E($1Y;B 9G *2!D>6Y&=6YC.PT* M"6%L:6%S(&1Y;D9U;F,N=7-E('5S93L-" EA;&EA<R!D>6Y&=6YC+G)E<75I M<F4 <F5Q=6ER93L-"GT-"G1E;7!L871E($1Y;D9U;F,H($QI;FMA9V4 5" Z M($QI;FMA9V4N1"P 4B Z('9O:60L(% P+"!0,2 I('L-" EI;G-T86YC92!$ M>6Y0<F]C*"!4+"!0,"P 4#$ *2!R96%L5&5M<&QA=&4[#0H)86QI87, <F5A M;%1E;7!L871E+F5R9B!E<F8[#0H)86QI87, <F5A;%1E;7!L871E+F9P(&9P M.PT*"6%L:6%S(')E86Q496UP;&%T92YU<V4 =7-E.PT*"6%L:6%S(')E86Q4 M96UP;&%T92YR97%U:7)E(')E<75I<F4[#0I]#0IT96UP;&%T92!$>6Y&=6YC M*"!,:6YK86=E(%0 .B!,:6YK86=E+E=I;F1O=W,L(%( .B!V;VED+"!0,"P M4#$ *2![#0H):6YS=&%N8V4 1'EN4')O8R 5"P 4# L(% Q("D <F5A;%1E M;7!L871E.PT*"6%L:6%S(')E86Q496UP;&%T92YE<F8 97)F.PT*"6%L:6%S M(')E86Q496UP;&%T92YF<"!F<#L-" EA;&EA<R!R96%L5&5M<&QA=&4N=7-E M('5S93L-" EA;&EA<R!R96%L5&5M<&QA=&4N<F5Q=6ER92!R97%U:7)E.PT* M?0T*=&5M<&QA=&4 1'EN1G5N8R 3&EN:V%G92!4(#H 3&EN:V%G92Y#+"!2 M(#H =F]I9"P 4# L(% Q("D >PT*"6EN<W1A;F-E($1Y;E!R;V,H(%0L(% P M+"!0,2 I(')E86Q496UP;&%T93L-" EA;&EA<R!R96%L5&5M<&QA=&4N97)F M(&5R9CL-" EA;&EA<R!R96%L5&5M<&QA=&4N9G 9G [#0H)86QI87, <F5A M;%1E;7!L871E+G5S92!U<V4[#0H)86QI87, <F5A;%1E;7!L871E+G)E<75I M<F4 <F5Q=6ER93L-"GT-" T*=&5M<&QA=&4 1'EN1G5N8R 3&EN:V%G92!4 M(#H 3&EN:V%G92Y$+"!2+"!0,"P 4#$ *2![#0H)4B!E<F8H(% P(' P+"!0 M,2!P,2 I('L =&AR;W< ;F5W($5X8V5P=&EO;B (E-H87)E9"!&=6YC=&EO M;B!N;W0 ;&]A9&5D(B I.R!R971U<FX 4BYI;FET.R!]( T*"71Y<&5D968 M4B H*B!F<"DH4# L4#$I(#T )F5R9CL-" EI;G-T86YC92!$>6XH(&9P("D M9'EN1G5N8SL-" EA;&EA<R!D>6Y&=6YC+G5S92!U<V4[#0H)86QI87, 9'EN M1G5N8RYR97%U:7)E(')E<75I<F4[#0I]#0IT96UP;&%T92!$>6Y&=6YC*"!, M:6YK86=E(%0 .B!,:6YK86=E+E=I;F1O=W,L(%(L(% P+"!0,2 I('L-" EE M>'1E<FXH(%=I;F1O=W, *2![#0H)"5( 97)F*"!0,"!P,"P 4#$ <#$ *2![ M('1H<F]W(&YE=R!%>&-E<'1I;VXH(")3:&%R960 1G5N8W1I;VX ;F]T(&QO M861E9"( *3L <F5T=7)N(%(N:6YI=#L ?2 -" D)='EP961E9B!2(" J(&9P M*2A0,"Q0,2D /2 F97)F.PT*"7T-" EI;G-T86YC92!$>6XH(&9P("D 9'EN M1G5N8SL-" EA;&EA<R!D>6Y&=6YC+G5S92!U<V4[#0H)86QI87, 9'EN1G5N M8RYR97%U:7)E(')E<75I<F4[#0I]#0IT96UP;&%T92!$>6Y&=6YC*"!,:6YK M86=E(%0 .B!,:6YK86=E+D,L(%(L(% P+"!0,2 I('L-" EE>'1E<FX *"!# M("D >PT*"0E2(&5R9B 4# <# L(% Q(' Q("D >R!T:')O=R!N97< 17AC M97!T:6]N*" B4VAA<F5D($9U;F-T:6]N(&YO="!L;V%D960B("D[(')E='5R M;B!2+FEN:70[('T #0H)"71Y<&5D968 4B H*B!F<"DH4# L4#$I(#T )F5R M9CL-" E]#0H):6YS=&%N8V4 1'EN*"!F<" I(&1Y;D9U;F,[#0H)86QI87, M9'EN1G5N8RYU<V4 =7-E.PT*"6%L:6%S(&1Y;D9U;F,N<F5Q=6ER92!R97%U M:7)E.PT*?0T*=&5M<&QA=&4 1'EN1G5N8R 3&EN:V%G92!4(#H 3&EN:V%G M92Y$+"!2(#H =F]I9"P 4# L(% Q+"!0,B I('L-" EI;G-T86YC92!$>6Y0 M<F]C*"!4+"!0,"P 4#$L(% R("D <F5A;%1E;7!L871E.PT*"6%L:6%S(')E M86Q496UP;&%T92YE<F8 97)F.PT*"6%L:6%S(')E86Q496UP;&%T92YF<"!F M<#L-" EA;&EA<R!R96%L5&5M<&QA=&4N=7-E('5S93L-" EA;&EA<R!R96%L M5&5M<&QA=&4N<F5Q=6ER92!R97%U:7)E.PT*?0T*=&5M<&QA=&4 1'EN1G5N M8R 3&EN:V%G92!4(#H 3&EN:V%G92Y7:6YD;W=S+"!2(#H =F]I9"P 4# L M(% Q+"!0,B I('L-" EI;G-T86YC92!$>6Y0<F]C*"!4+"!0,"P 4#$L(% R M("D <F5A;%1E;7!L871E.PT*"6%L:6%S(')E86Q496UP;&%T92YE<F8 97)F M.PT*"6%L:6%S(')E86Q496UP;&%T92YF<"!F<#L-" EA;&EA<R!R96%L5&5M M<&QA=&4N=7-E('5S93L-" EA;&EA<R!R96%L5&5M<&QA=&4N<F5Q=6ER92!R M97%U:7)E.PT*?0T*=&5M<&QA=&4 1'EN1G5N8R 3&EN:V%G92!4(#H 3&EN M:V%G92Y#+"!2(#H =F]I9"P 4# L(% Q+"!0,B I('L-" EI;G-T86YC92!$ M>6Y0<F]C*"!4+"!0,"P 4#$L(% R("D <F5A;%1E;7!L871E.PT*"6%L:6%S M(')E86Q496UP;&%T92YE<F8 97)F.PT*"6%L:6%S(')E86Q496UP;&%T92YF M<"!F<#L-" EA;&EA<R!R96%L5&5M<&QA=&4N=7-E('5S93L-" EA;&EA<R!R M96%L5&5M<&QA=&4N<F5Q=6ER92!R97%U:7)E.PT*?0T*+RH-"G1E;7!L871E M($1Y;D9U;F,H($QI;FMA9V4 5"P 4B Z('9O:60L(% P+"!0,2P 4#( *2![ M#0H):6YS=&%N8V4 1'EN4')O8R 5"P 4# L(% Q+"!0,B I(')E86Q496UP M;&%T93L-" EA;&EA<R!R96%L5&5M<&QA=&4N97)F(&5R9CL-" EA;&EA<R!R M96%L5&5M<&QA=&4N9G 9G [#0H)86QI87, <F5A;%1E;7!L871E+G5S92!U M<V4[#0H)86QI87, <F5A;%1E;7!L871E+G)E<75I<F4 <F5Q=6ER93L-"GT- M"BHO#0IT96UP;&%T92!$>6Y&=6YC*"!,:6YK86=E(%0 .B!,:6YK86=E+D0L M(%(L(% P+"!0,2P 4#( *2![#0H)4B!E<F8H(% P(' P+"!0,2!P,2P 4#( M<#( *2![('1H<F]W(&YE=R!%>&-E<'1I;VXH(")3:&%R960 1G5N8W1I;VX M;F]T(&QO861E9"( *3L <F5T=7)N(%(N:6YI=#L ?2 -" ET>7!E9&5F(%( M*"IF<"DH4# L(% Q+"!0,BD /2 F97)F.PT*"6EN<W1A;F-E($1Y;B 9G M*2!D>6Y&=6YC.PT*"6%L:6%S(&1Y;D9U;F,N=7-E('5S93L-" EA;&EA<R!D M>6Y&=6YC+G)E<75I<F4 <F5Q=6ER93L-"GT-"G1E;7!L871E($1Y;D9U;F,H M($QI;FMA9V4 5" Z($QI;FMA9V4N5VEN9&]W<RP 4BP 4# L(% Q+"!0,B I M('L-" EE>'1E<FX *"!7:6YD;W=S("D >PT*"0E2(&5R9B 4# <# L(% Q M(' Q+"!0,B!P,B I('L =&AR;W< ;F5W($5X8V5P=&EO;B (E-H87)E9"!& M=6YC=&EO;B!N;W0 ;&]A9&5D(B I.R!R971U<FX 4BYI;FET.R!]( T*"0ET M>7!E9&5F(%( *"IF<"DH4# L(% Q+"!0,BD /2 F97)F.PT*"7T-" EI;G-T M86YC92!$>6XH(&9P("D 9'EN1G5N8SL-" EA;&EA<R!D>6Y&=6YC+G5S92!U M<V4[#0H)86QI87, 9'EN1G5N8RYR97%U:7)E(')E<75I<F4[#0I]#0IT96UP M;&%T92!$>6Y&=6YC*"!,:6YK86=E(%0 .B!,:6YK86=E+D,L(%(L(% P+"!0 M,2P 4#( *2![#0H)97AT97)N(" 0R I('L-" D)4B!E<F8H(% P(' P+"!0 M,2!P,2P 4#( <#( *2![('1H<F]W(&YE=R!%>&-E<'1I;VXH(")3:&%R960 M1G5N8W1I;VX ;F]T(&QO861E9"( *3L <F5T=7)N(%(N:6YI=#L ?2 -" D) M='EP961E9B!2(" J9G I*% P+"!0,2P 4#(I(#T )F5R9CL-" E]#0H):6YS M=&%N8V4 1'EN*"!F<" I(&1Y;D9U;F,[#0H)86QI87, 9'EN1G5N8RYU<V4 L=7-E.PT*"6%L:6%S(&1Y;D9U;F,N<F5Q=6ER92!R97%U:7)E.PT*?0T*#0H` ` end begin 666 winmm.d M;6]D=6QE('=I;F5X+G=I;FUM.PT*#0II;7!O<G0 =VEN97 N9'EN;&]A9&5R M.PT*#0IA;&EA<R!U:6YT($U-4D5354Q4.R ("\J(&5R<F]R(')E='5R;B!C M;V1E+" P(&UE86YS(&YO(&5R<F]R("HO#0H-"FEN<W1A;F-E($1Y;D9U;F,H M(%=I;F1O=W,L($U-4D5354Q4+"!U:6YT("D 25])7TQD<CL-"FEN<W1A;F-E M($1Y;D9U;F,H(%=I;F1O=W,L($173U)$("D 25]67TQD<CL-" T*25])7TQD M<BYF<"!T:6UE0F5G:6Y097)I;V0[#0I)7TE?3&1R+F9P('1I;65%;F1097)I M;V0[#0I)7U9?3&1R+F9P('1I;65'9714:6UE.PT*#0IS=&%T:6, =&AI<R I M#0I[#0H)=&EM94)E9VEN4&5R:6]D(#T 25])7TQD<BYR97%U:7)E*" B=VEN M;6TN9&QL(BP (G1I;65"96=I;E!E<FEO9"( *3L-" E)7TE?3&1R+G5S92 M=&EM945N9%!E<FEO9"P (" B=VEN;6TN9&QL(BP (G1I;65%;F1097)I;V0B M("D[#0H)25]67TQD<BYU<V4H('1I;65'9714:6UE+" (" (G=I;FUM+F1L 9;"(L(")T:6UE1V5T5&EM92( *3L-"GT-" `` ` end
Aug 12 2003
parent reply "Mårten Ask" <majbritt37 hotmail.com> writes:
Thanks!

I haven't had time to try it out yet..

There's still one thing that puzzles me though. Structs. how do I declare
that I want a struct from the dll? From the imagemagick api:

typedef struct _MagickWand
  MagickWand;
  ...
extern MagickExport MagickWand
  *MagickCloneWand(const MagickWand *),
  *MagickCoalesceImages(MagickWand *),
  *NewMagickWand(void);
  ...

Obviously I need to declare those functions as 'extern (C) MagickWand
NewMagickWand()' but then the compiler complains about not knowing what a
MagickWand is. Do I write 'extern (C) struct MagickWand'? Or 'extern (C)
typedef MagickWand'?



"Mike Wynn" <mike.wynn l8night.co.uk> skrev i meddelandet
news:bhbaa0$1ftb$1 digitaldaemon.com...
 here's a templated class lib I wrote to help with dll loading ('cos I like
 the delphi extern "foo.dll"; )
 and an example (loads winmm.dll to all access to multimedia timers)
 due to D's templateing its a little verbose, but works ...

 first make instances of the types of functions you want to import
 e.g. `extern (windows) DWORD func();`
 instance DynFunc( Windows, DWORD ) noParamReturnsDword;

 the declare a func pointer to it (using the template instance)
 `<instance>.fp` e.g. ....
 noParamReturnsDword.fp myFunc;

 // now write a static initialiser to your module to load the dll and get
the
 function.
 // there are two ways to do this both have the same result but its
personal
 preference which you use
 static this()
 {
 // fp = <template>.require( <dll name>, <func_name> ); // I perfer this
 myFunc = I_I_Ldr.require( "foo.dll", "someFuncname" );
 // <template>.use( fp, <dll name>, <func_name> );
 noParamReturnsDword.use( myFunc,   "foo.dll", "someFuncname" );
 }

 for C fucntions use
 instance DynFunc( C, <return_type>, <param1>, <param2> .... ) somename;
 if the return type is void due to D templates you can't use
 instance DynFunc( C, void, int );
 instead you have to use DynProc( C, int );
 or DyncProc( C ) => extern(C) void func( void );

 to do it manually here the code that loads up and gets a directx d3d
 interface from the function
 `Direct3DCreate8` in `d3d8.dll`

 extern(Windows) alias IDirect3D8 function( UINT ) start_up_fp;

 IDirect3D8 loadD3DLibs() {
  HMODULE sysModule;
  sysModule = LoadLibraryA( "d3d8.dll" );   // load a dll
  FARPROC fp = GetProcAddress( sysModule, cast(char*)"Direct3DCreate8" );
//
 get a function pointer
  assert(fp);
  start_up_fp dxfp = cast(start_up_fp)fp;
  return dxfp(D3D_SDK_VERSION);
 }

 failing all that .... use implib to convert the dll to a .lib and just
write
 the functions as
 extern( C ) .....
 or extern(Windows) .....
 the linker will the link correctly against <foo>.dll if you link against
the
 created lib file.


 "Mårten Ask" <majbritt37 hotmail.com> wrote in message
 news:bhb9cs$1eq3$1 digitaldaemon.com...
 Hi,

 I want to use som functions from the imagemagick C api. How do I do
that?
 How do I call the functions and objects and how do I link with the
dll's?

Aug 15 2003
parent "Mike Wynn" <mike.wynn l8night.co.uk> writes:
"Mårten Ask" <majbritt37 hotmail.com> wrote in message
news:bhjaf3$348$1 digitaldaemon.com...
 Thanks!

 I haven't had time to try it out yet..

 There's still one thing that puzzles me though. Structs. how do I declare
 that I want a struct from the dll? From the imagemagick api:
the compiler only needs to know about the struct layout, this is usually in the c header some times you will find typedef struct _foo { } * ApiToken; either way the dll does not "export" the struct layout. if the dll contains a struct then I assume its struct foo { int a; } extern (C) foo in_dll; I've only every used "getProcAddress" or implicit linking I'm not sure what VC++/Windows does with dll's contain data too, guess I better read some docs might be useful!! read on about how to declare the struct;
 typedef struct _MagickWand
   MagickWand;
   ...
 extern MagickExport MagickWand
   *MagickCloneWand(const MagickWand *),
   *MagickCoalesceImages(MagickWand *),
   *NewMagickWand(void);
you need to know what the _MagicWand struct looks like .. also note the use of align. struct Foo { align(1): byte a, b; int missaligned; }; struct Foo2 { align(4): byte a, b; int aligned; align(1): byte c; int offby1; }; (the default for D and C is to align items at their size (works on CISC and RISC then)) only the functions need to be extern(C) etc extern(C) : Foo * getFooFromFoo2( Foo2* ); Foo* getContext(); etc... asfaik (Walter correct me here if I'm wrong) the only time making a struct, alias or typedef as extern(CONV) is if it contains a pointer to func that you want to have that calling convention. although is does help document the code to have extern(C) struct MyStruct { align(4): int a, b, c, d; } (implies that its for use with extern(C) funcs).
   ...

 Obviously I need to declare those functions as 'extern (C) MagickWand
 NewMagickWand()' but then the compiler complains about not knowing what a
 MagickWand is. Do I write 'extern (C) struct MagickWand'? Or 'extern (C)
 typedef MagickWand'?



 "Mike Wynn" <mike.wynn l8night.co.uk> skrev i meddelandet
 news:bhbaa0$1ftb$1 digitaldaemon.com...
 here's a templated class lib I wrote to help with dll loading ('cos I
like
 the delphi extern "foo.dll"; )
 and an example (loads winmm.dll to all access to multimedia timers)
 due to D's templateing its a little verbose, but works ...

 first make instances of the types of functions you want to import
 e.g. `extern (windows) DWORD func();`
 instance DynFunc( Windows, DWORD ) noParamReturnsDword;

 the declare a func pointer to it (using the template instance)
 `<instance>.fp` e.g. ....
 noParamReturnsDword.fp myFunc;

 // now write a static initialiser to your module to load the dll and get
the
 function.
 // there are two ways to do this both have the same result but its
personal
 preference which you use
 static this()
 {
 // fp = <template>.require( <dll name>, <func_name> ); // I perfer this
 myFunc = I_I_Ldr.require( "foo.dll", "someFuncname" );
 // <template>.use( fp, <dll name>, <func_name> );
 noParamReturnsDword.use( myFunc,   "foo.dll", "someFuncname" );
 }

 for C fucntions use
 instance DynFunc( C, <return_type>, <param1>, <param2> .... ) somename;
 if the return type is void due to D templates you can't use
 instance DynFunc( C, void, int );
 instead you have to use DynProc( C, int );
 or DyncProc( C ) => extern(C) void func( void );

 to do it manually here the code that loads up and gets a directx d3d
 interface from the function
 `Direct3DCreate8` in `d3d8.dll`

 extern(Windows) alias IDirect3D8 function( UINT ) start_up_fp;

 IDirect3D8 loadD3DLibs() {
  HMODULE sysModule;
  sysModule = LoadLibraryA( "d3d8.dll" );   // load a dll
  FARPROC fp = GetProcAddress( sysModule, cast(char*)"Direct3DCreate8" );
//
 get a function pointer
  assert(fp);
  start_up_fp dxfp = cast(start_up_fp)fp;
  return dxfp(D3D_SDK_VERSION);
 }

 failing all that .... use implib to convert the dll to a .lib and just
write
 the functions as
 extern( C ) .....
 or extern(Windows) .....
 the linker will the link correctly against <foo>.dll if you link against
the
 created lib file.


 "Mårten Ask" <majbritt37 hotmail.com> wrote in message
 news:bhb9cs$1eq3$1 digitaldaemon.com...
 Hi,

 I want to use som functions from the imagemagick C api. How do I do
that?
 How do I call the functions and objects and how do I link with the
dll's?

Aug 15 2003