mirror of https://github.com/adamdruppe/arsd.git
Use VARENUM
This commit is contained in:
parent
b4b8bbcc6b
commit
4b7f71a2dc
43
com.d
43
com.d
|
@ -250,11 +250,11 @@ struct ComResult {
|
||||||
|
|
||||||
T getD(T)() {
|
T getD(T)() {
|
||||||
switch(result.vt) {
|
switch(result.vt) {
|
||||||
case Vt.long_: // int
|
case VARENUM.VT_I4: // int
|
||||||
static if(is(T : const long))
|
static if(is(T : const long))
|
||||||
return result.intVal;
|
return result.intVal;
|
||||||
throw new Exception("cannot convert variant of type int to requested " ~ T.stringof);
|
throw new Exception("cannot convert variant of type int to requested " ~ T.stringof);
|
||||||
case Vt.string_:
|
case VARENUM.VT_BSTR:
|
||||||
static if(is(T : const string))
|
static if(is(T : const string))
|
||||||
return makeUtf8StringFromWindowsString(result.bstrVal); // FIXME free?
|
return makeUtf8StringFromWindowsString(result.bstrVal); // FIXME free?
|
||||||
throw new Exception("cannot convert variant of type string to requested " ~ T.stringof);
|
throw new Exception("cannot convert variant of type string to requested " ~ T.stringof);
|
||||||
|
@ -720,29 +720,6 @@ auto getComObject(T = Dynamic)(wstring c, bool tryCreateIfGetFails = true) {
|
||||||
// FIXME: add one to get by ProgID rather than always guid
|
// FIXME: add one to get by ProgID rather than always guid
|
||||||
// FIXME: add a dynamic com object that uses IDispatch
|
// FIXME: add a dynamic com object that uses IDispatch
|
||||||
|
|
||||||
/// Variant Type
|
|
||||||
/// https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/vartype-function
|
|
||||||
private enum Vt
|
|
||||||
{
|
|
||||||
empty = 0,
|
|
||||||
null_ = 1,
|
|
||||||
integer = 2,
|
|
||||||
long_ = 3,
|
|
||||||
single = 4,
|
|
||||||
double_ = 5,
|
|
||||||
currency = 6,
|
|
||||||
date = 7,
|
|
||||||
string_ = 8,
|
|
||||||
object = 9,
|
|
||||||
error = 10,
|
|
||||||
boolean = 11,
|
|
||||||
variant = 12,
|
|
||||||
dataObject = 13,
|
|
||||||
decimal = 14,
|
|
||||||
byte_ = 17,
|
|
||||||
longLong = 20,
|
|
||||||
}
|
|
||||||
|
|
||||||
/* COM SERVER CODE */
|
/* COM SERVER CODE */
|
||||||
|
|
||||||
T getFromVariant(T)(VARIANT arg) {
|
T getFromVariant(T)(VARIANT arg) {
|
||||||
|
@ -751,31 +728,31 @@ T getFromVariant(T)(VARIANT arg) {
|
||||||
static if(is(T == void)) {
|
static if(is(T == void)) {
|
||||||
return;
|
return;
|
||||||
} else static if(is(T == int)) {
|
} else static if(is(T == int)) {
|
||||||
if(arg.vt == Vt.long_)
|
if(arg.vt == VARENUM.VT_I4)
|
||||||
return arg.intVal;
|
return arg.intVal;
|
||||||
} else static if (is(T == float)) {
|
} else static if (is(T == float)) {
|
||||||
if(arg.vt == Vt.single)
|
if(arg.vt == VARENUM.VT_R4)
|
||||||
return arg.fltVal;
|
return arg.fltVal;
|
||||||
} else static if (is(T == double)) {
|
} else static if (is(T == double)) {
|
||||||
if(arg.vt == Vt.double_)
|
if(arg.vt == VARENUM.VT_R8)
|
||||||
return arg.dblVal;
|
return arg.dblVal;
|
||||||
} else static if(is(T == bool)) {
|
} else static if(is(T == bool)) {
|
||||||
if(arg.vt == Vt.boolean)
|
if(arg.vt == VARENUM.VT_BOOL)
|
||||||
return arg.boolVal ? true : false;
|
return arg.boolVal ? true : false;
|
||||||
} else static if(is(T == string)) {
|
} else static if(is(T == string)) {
|
||||||
if(arg.vt == Vt.string_) {
|
if(arg.vt == VARENUM.VT_BSTR) {
|
||||||
auto str = arg.bstrVal;
|
auto str = arg.bstrVal;
|
||||||
scope(exit) SysFreeString(str);
|
scope(exit) SysFreeString(str);
|
||||||
return to!string(str[0 .. SysStringLen(str)]);
|
return to!string(str[0 .. SysStringLen(str)]);
|
||||||
}
|
}
|
||||||
} else static if(is(T == IDispatch)) {
|
} else static if(is(T == IDispatch)) {
|
||||||
if(arg.vt == Vt.object)
|
if(arg.vt == VARENUM.VT_DISPATCH)
|
||||||
return arg.pdispVal;
|
return arg.pdispVal;
|
||||||
} else static if(is(T : IUnknown)) {
|
} else static if(is(T : IUnknown)) {
|
||||||
// if(arg.vt == 13)
|
// if(arg.vt == 13)
|
||||||
static assert(0);
|
static assert(0);
|
||||||
} else static if(is(T == ComClient!(D, I), D, I)) {
|
} else static if(is(T == ComClient!(D, I), D, I)) {
|
||||||
if(arg.vt == 9)
|
if(arg.vt == VARENUM.VT_DISPATCH)
|
||||||
return ComClient!(D, I)(arg.pdispVal);
|
return ComClient!(D, I)(arg.pdispVal);
|
||||||
} else static if(is(T == E[], E)) {
|
} else static if(is(T == E[], E)) {
|
||||||
if(arg.vt & 0x2000) {
|
if(arg.vt & 0x2000) {
|
||||||
|
@ -817,7 +794,7 @@ T getFromVariant(T)(VARIANT arg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new Exception("Type mismatch, needed "~ T.stringof ~" got " ~ to!string(cast(Vt) arg.vt));
|
throw new Exception("Type mismatch, needed "~ T.stringof ~" got " ~ to!string(cast(VARENUM) arg.vt));
|
||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue