From f8f5592132c880aa611fbab1021aacc5e02c3fd4 Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Thu, 4 Jul 2024 13:03:15 +0200 Subject: [PATCH] com.getD: Remove redundant variant logic --- com.d | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/com.d b/com.d index 70bd4f2..035e0b8 100644 --- a/com.d +++ b/com.d @@ -250,20 +250,7 @@ struct ComResult { } T getD(T)() { - switch(result.vt) { - case VARENUM.VT_I4: // int - static if(is(T : const long)) - return result.intVal; - throw new Exception("cannot convert variant of type int to requested " ~ T.stringof); - case VARENUM.VT_BSTR: - static if(is(T : const string)) - return makeUtf8StringFromWindowsString(result.bstrVal); // FIXME free? - throw new Exception("cannot convert variant of type string to requested " ~ T.stringof); - default: - return getFromVariant!T(result); - - //throw new Exception("can't handle this type " ~ to!string(result.vt)); - } + return getFromVariant!T(result); } } @@ -658,6 +645,9 @@ VARIANT toComVariant(T)(T arg) { ret = arg._fetchProperty(); } else static if (is(T : ComResult)) { ret = arg.result; + } else static if(is(T : IDispatch)) { + ret.vt = VARENUM.VT_DISPATCH; + ret.pdispVal = arg; } else static if(is(T : int)) { ret.vt = 3; ret.intVal = arg;