在我通过VC 2012的应用程序中,ready函数需要“ VARIANT”值作为输入。我有一个“双”变量。以下是我厌倦了无效的转换。在线搜索并找不到答案。请指教。谢谢。
double db=19;
VARIANT v;
v.dblVal=19;
答案 0 :(得分:2)
在其中一个窗口文件的注释下方,将简要介绍受支持的数据类型 VARIANT
/*
* VARENUM usage key,
*
* * [V] - may appear in a VARIANT
* * [T] - may appear in a TYPEDESC
* * [P] - may appear in an OLE property set
* * [S] - may appear in a Safe Array
* * [C] - supported by class _variant_t
*
*
* VT_EMPTY [V] [P] nothing
* VT_NULL [V] [P] SQL style Null
* VT_I2 [V][T][P][S][C] 2 byte signed int
* VT_I4 [V][T][P][S][C] 4 byte signed int
* VT_R4 [V][T][P][S][C] 4 byte real
* VT_R8 [V][T][P][S][C] 8 byte real
* VT_CY [V][T][P][S][C] currency
* VT_DATE [V][T][P][S][C] date
* VT_BSTR [V][T][P][S][C] OLE Automation string
* VT_DISPATCH [V][T][P][S][C] IDispatch *
* VT_ERROR [V][T] [S][C] SCODE
* VT_BOOL [V][T][P][S][C] True=-1, False=0
* VT_VARIANT [V][T][P][S] VARIANT *
* VT_UNKNOWN [V][T] [S][C] IUnknown *
* VT_DECIMAL [V][T] [S][C] 16 byte fixed point
* VT_I1 [T] signed char
* VT_UI1 [V][T][P][S][C] unsigned char
* VT_UI2 [T][P] unsigned short
* VT_UI4 [T][P] unsigned short
* VT_I8 [T][P] signed 64-bit int
* VT_UI8 [T][P] unsigned 64-bit int
* VT_INT [T] signed machine int
* VT_UINT [T] unsigned machine int
* VT_VOID [T] C style void
* VT_HRESULT [T] Standard return type
* VT_PTR [T] pointer type
* VT_SAFEARRAY [T] (use VT_ARRAY in VARIANT)
* VT_CARRAY [T] C style array
* VT_USERDEFINED [T] user defined type
* VT_LPSTR [T][P] null terminated string
* VT_LPWSTR [T][P] wide null terminated string
* VT_FILETIME [P] FILETIME
* VT_BLOB [P] Length prefixed bytes
* VT_STREAM [P] Name of the stream follows
* VT_STORAGE [P] Name of the storage follows
* VT_STREAMED_OBJECT [P] Stream contains an object
* VT_STORED_OBJECT [P] Storage contains an object
* VT_BLOB_OBJECT [P] Blob contains an object
* VT_CF [P] Clipboard format
* VT_CLSID [P] A Class ID
* VT_VECTOR [P] simple counted array
* VT_ARRAY [V] SAFEARRAY*
* VT_BYREF [V] void* for local use
*/
您应该使用 _variant_t 而不是 VARIANT 。 下面的代码会将您的double值转换为变体,
_variant_t var(10.52);