1 /** 2 Wraps calls to xlXXX "functions" via the Excel4/Excel12 functions 3 */ 4 module xlld.xl; 5 6 import xlld.xlcall: XLOPER12, LPXLOPER12; 7 8 version(unittest) { 9 10 11 } 12 13 XLOPER12 coerce(LPXLOPER12 oper) nothrow @nogc @trusted { 14 import xlld.framework: Excel12f; 15 import xlld.xlcall: xlCoerce; 16 17 XLOPER12 coerced; 18 LPXLOPER12[1] arg = [oper]; 19 Excel12f(xlCoerce, &coerced, arg); 20 return coerced; 21 } 22 23 void free(ref XLOPER12 oper) nothrow @nogc @trusted { 24 free(&oper); 25 } 26 27 void free(LPXLOPER12 oper) nothrow @nogc @trusted { 28 import xlld.framework: Excel12f; 29 import xlld.xlcall: xlFree; 30 31 LPXLOPER12[1] arg = [oper]; 32 Excel12f(xlFree, null, arg); 33 } 34 35 36 struct Coerced { 37 XLOPER12 oper; 38 private bool coerced; 39 40 alias oper this; 41 42 43 this(LPXLOPER12 oper) @safe @nogc nothrow { 44 this.oper = coerce(oper); 45 this.coerced = true; 46 } 47 48 ~this() @safe @nogc nothrow { 49 if(coerced) free(oper); 50 } 51 } 52 53 /** 54 Coerces an oper and returns an RAII struct that automatically frees memory 55 */ 56 auto scopedCoerce(LPXLOPER12 oper) @safe @nogc nothrow { 57 return Coerced(oper); 58 }