#include "StdAfx.h"
#include "VariantConvert.h"
CVariantConvert::CVariantConvert(void)
{
}
CVariantConvert::~CVariantConvert(void)
{
}
/************************************************************************/
/* Function Name:
* short2Variant- convert short Integer data type to VARIANT data type
* Input Argument:
* short sData-a data of short integer type
* VARIANT va- a data of VARIANT type
* Author:
* liyy
* Date:
2010.08.03
*/
/************************************************************************/
void CVariantConvert::short2Variant(short sData,VARIANT &va)
{
va.vt=VT_I2;
va.iVal = sData;
}
/************************************************************************/
/* Function Name:
* long2Variant- convert long Integer data type to VARIANT data type
* Input Argument:
* long sData-a data of long integer type
* VARIANT va- a data of VARIANT type
* Author:
* liyy
* Date:
2010.08.03
*/
/************************************************************************/
void CVariantConvert:: long2Variant(long lData,VARIANT& va)
{
va.vt = VT_I4;
va.lVal = lData;
}
/************************************************************************/
/* Function Name:
* float2Variant- convert float data type to VARIANT data type
* Input Argument:
* float sData-a data of float data type
* VARIANT va- a data of VARIANT data type
* Author:
* liyy
* Date:
*2010.08.03
*/
/************************************************************************/
void CVariantConvert::float2Variant(float fData, VARIANT& va)
{
va.vt = VT_R4;
va.fltVal = fData;
}
/************************************************************************/
/* Function Name:
* double2Variant- convert double data type to VARIANT data type
* Input Argument:
* double dData-a data of double data type
* VARIANT va- a data of VARIANT data type
* Author:
* liyy
* Date:
* 2010.08.03
*/
/************************************************************************/
void CVariantConvert::double2Variant(double dData,VARIANT &va)
{
va.vt = VT_R8;
va.dblVal = dData;
}
/************************************************************************/
/* Function Name:
* unChar2Variant- convert unsigned char data type to VARIANT data type
* Input Argument:
* unsigned char chData-a data of unsigned char data type
* VARIANT va- a data of VARIANT data type
* Author:
* liyy
* Date:
* 2010.08.03
*/
/************************************************************************/
void CVariantConvert::unChar2Variant(unsigned char chData,VARIANT &va)
{
va.vt = VT_UI1;
va.bVal = chData;
}
/************************************************************************/
/* Function Name:
* arrayDouble2Variant- convert double array to VARIANT data type
* Input Argument:
* double *pArray-a pointer that point to the array
* int iDim - the dimension of the array
* int iDim1Num- the size of the 1st dimension in this array
* int iDim2Num -the size of the 2st dimension in this array
* VARIANT va- a data of VARIANT data type
* Author:
* liyy
* Date:
* 2010.08.03
*/
/************************************************************************/
void CVariantConvert::arrayDouble2Variant(double *pArray,int iDim,int iDim1Num,int iDim2Num,VARIANT &vaArray)
//void arrayDouble2Variant(double pArray[][],int iDim,int iDim1Num,int iDim2Num,VARIANT &vaArray);
{
// if (iDim ==1)
// {
// iDim2Num = 0;
// }
// else if (iDim ==2)
// {
// ;
// }
// ()
// {
// //iDim2Num = iDim2Num;
// }
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[2]; // 二维需要定义两个元素
rgsabound[0].lLbound = 0; // 一维的下界(下界就是下标的最小值)
rgsabound[0].cElements =iDim1Num; // 一维的元素的个数
rgsabound[1].lLbound = 0; // 二维的下界
rgsabound[1].cElements = iDim2Num; // 二维的元素的个数
long lIndex[2]; // 定义索引
psa = SafeArrayCreate(VT_R8, 2, rgsabound); // 按照二维数组分配空间
for ( long k = 0; k < (long)iDim1Num; k++)
{
lIndex[0] = k;
for (long num = 0; num < (long)4; num++ )
{
lIndex[1] = num;
SafeArrayPutElement (psa, lIndex, &pArray[k*iDim2Num+num]); // lIndex作为SAFEARRAY中的索引。
}
}
vaArray.vt = VT_ARRAY|VT_R8; // 类型
vaArray.parray = psa; // 赋值
}
/************************************************************************/
/* Function Name:
* arrayDouble2Variant- reload the function of arraDouble2Variant
* Input Argument:
* double *pArray-a pointer that point to the array
* int iDim - the dimension of the array
* int iDimLength- the size of the 1st dimension in this array
* VARIANT va- a data of VARIANT data type
* Author:
* liyy
* Date:
* 2010.08.03
*/
/************************************************************************/
void CVariantConvert::arrayDouble2Variant(double *pArray,int iDim,int iDimlength,VARIANT &vaArray)
{
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound=0;
rgsabound[0].cElements=iDimlength;
psa = SafeArrayCreate(VT_R8,iDim,rgsabound);
long lIndex[1];
for (int k=0; k < iDimlength;k++)
{
lIndex[0]=k;
SafeArrayPutElement(psa,lIndex,&pArray[k]);
}
vaArray.vt = VT_ARRAY|VT_R8;
vaArray.parray= psa;
}
/************************************************************************/
/* Function Name:
* arraylong2Variant- convert long array to VARIANT data type
* Input Argument:
* long *pArray-a pointer that point to the array
* int iDim - the dimension of the array
* int iDim1Num- the size of the 1st dimension in this array
* int iDim2Num -the size of the 2st dimension in this array
* VARIANT va- a data of VARIANT data type
* Author:
* liyy
* Date:
* 2010.08.04
*/
/************************************************************************/
void CVariantConvert::arraylong2Variant(long *pArray,int iDim,int iDim1Num,int iDim2Num,VARIANT& vaArray)
{
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[2]; // 二维需要定义两个元素
rgsabound[0].lLbound = 0; // 一维的下界
rgsabound[0].cElements =iDim1Num; // 一维的元素的个数
rgsabound[1].lLbound = 0; // 二维的下界
rgsabound[1].cElements = iDim2Num; // 二维的元素的个数
long lIndex[2]; // 定义索引
psa = SafeArrayCreate(VT_I4, 2, rgsabound); // 按照二维数组分配空间
for ( long k = 0; k < (long)iDim1Num; k++)
{
lIndex[0] = k;
for (long num = 0; num < (long)4; num++ )
{
lIndex[1] = num;
SafeArrayPutElement (psa, lIndex, &pArray[k*iDim2Num+num]); // lIndex作为SAFEARRAY中的索引。
}
}
vaArray.vt = VT_ARRAY|VT_I4;
vaArray.parray = psa;
}
/************************************************************************/
/* Function Name:
* arraylong2Variant- reload the function of arraylong2Variant
* Input Argument:
* long *pArray-a pointer that point to the array
* int iDim - the dimension of the array
* int iDimLength- the size of the 1st dimension in this array
matlab与c/c++混合编程中VARIANT与c++数据类型转换类
2星 需积分: 34 126 浏览量
2010-08-09
14:06:48
上传
评论
收藏 3KB RAR 举报
liyy011
- 粉丝: 12
- 资源: 3
最新资源
- 《Fundamentals of Power Electronics》翻译-3.1 直流变压器模型
- 111111111111111111
- Motorbike Physics Tool v1.5.6
- RF System Design ppt-射频系统设计
- torchvision resnet18 计算相似度
- 250+ Stylized Mountain & Cave Textures
- foobar2000v1.2.0.apk
- Web开发 技术关键词: React 内容关键词: 前端UI库 用途: 开发交互式用户界面
- 三菱PLC例程源码三菱CC-LINK配置和变频器通信程序(注释)
- 三菱PLC例程源码三菱A系列程序
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈