#include "converttype.h"
#include <QUuid>
IDispatch* to_dispatch(_variant_t arg) {
IDispatch *disp = 0;
if (arg.vt & VT_DISPATCH) {
if (arg.vt & VT_BYREF)
disp = *arg.ppdispVal;
else
disp = arg.pdispVal;
}
return disp;
LPWSTR toLPWSTR(QString str){
return (LPWSTR)(str.utf16());
QString from_guid(GUID guid) {
QUuid uuid(guid);
return uuid.toString();
GUID to_guid(QString suuid) {
QUuid uuid(suuid);
GUID guid;
guid.Data1 = uuid.data1;
guid.Data2 = uuid.data2;
guid.Data3 = uuid.data3;
for (int i=0;i<8;i++)
guid.Data4[i] = uuid.data4[i];
return guid;
_bstr_t to_bstr_t(QString str){
// return (_bstr_t)(str.utf16());
BSTR result= SysAllocStringLen(0, str.length());
str.toWCharArray(result);
return result;
QString from_bstr_t(_bstr_t str){
return QString::fromUtf16(reinterpret_cast<const ushort*>((const WCHAR*)str));
QVariant from_variant_t(const _variant_t &arg){
QVariant var;
switch(arg.vt) {
case VT_BSTR:
var = QString::fromWCharArray(arg.bstrVal);
break;
case VT_BSTR|VT_BYREF:
var = QString::fromWCharArray(*arg.pbstrVal);
case VT_BOOL:
var = QVariant((bool)arg.boolVal);
case VT_BOOL|VT_BYREF:
var = QVariant((bool)*arg.pboolVal);
case VT_I1:
var = arg.cVal;
/*if (typeName == "char")
type = QVariant::Int;*/
case VT_I1|VT_BYREF:
var = *arg.pcVal;
case VT_I2:
var = arg.iVal;
/*if (typeName == "short")
case VT_I2|VT_BYREF:
var = *arg.piVal;
case VT_I4:
var = (int)arg.lVal;
case VT_I4|VT_BYREF:
var = (int)*arg.plVal;
case VT_INT:
var = arg.intVal;
case VT_INT|VT_BYREF:
var = *arg.pintVal;
case VT_UI1:
var = arg.bVal;
case VT_UI1|VT_BYREF:
var = *arg.pbVal;
case VT_UI2:
var = arg.uiVal;
case VT_UI2|VT_BYREF:
var = *arg.puiVal;
case VT_UI4:
var = (int)arg.ulVal;
case VT_UI4|VT_BYREF:
var = (int)*arg.pulVal;
case VT_UINT:
var = arg.uintVal;
case VT_UINT|VT_BYREF:
var = *arg.puintVal;
case VT_CY:
var = arg.cyVal.int64;
case VT_CY|VT_BYREF:
var = arg.pcyVal->int64;
case VT_R4:
var = arg.fltVal;
case VT_R4|VT_BYREF:
var = *arg.pfltVal;
case VT_R8:
var = arg.dblVal;
case VT_R8|VT_BYREF:
var = *arg.pdblVal;
return var;