29 #if defined(_USE_WIN_API) 31 #elif defined(_USE_LINUX_API) 37 #define _wcsicmp wcscasecmp 50 #define _LEN_VARIANT2BSTR (500) 82 minlen =
sizeof(wchar_t) * (cch + 1);
83 bstr = (
BSTR) malloc(minlen);
86 memset(bstr, 0, minlen);
90 minlen = (cch < minlen ? cch : minlen);
91 memcpy(bstr, pch,
sizeof(
wchar_t) * minlen);
190 psa->
pvData = malloc(cElements * sz);
192 if (psa->
pvData == NULL) {
198 memset(psa->
pvData, 0, cElements * sz);
217 if (psa->
pvData != NULL) {
280 if (psa == NULL || plLbound == NULL)
282 if (nDim <= 0 || psa->cDims < nDim)
300 if (psa == NULL || plUbound == NULL)
302 if (nDim <= 0 || psa->cDims < nDim)
320 if (psa == NULL || pvt == NULL)
338 if (psa == NULL || ppvData == NULL)
371 memset(pvarg, 0,
sizeof(
VARIANT));
386 if (pvarg->
parray != NULL) {
397 memset(pvarg, 0,
sizeof(
VARIANT));
401 #if (_DN_USE_VARIANT_API) 411 if ((pvargDest == NULL) || (pvargSrc == NULL)) {
415 if (pvargDest == pvargSrc) {
442 pvargDest->
vt = pvargSrc->
vt;
446 cbElements * cElements);
449 pvargDest->
vt = pvargSrc->
vt;
451 for (i = 0; i < cElements; i++) {
457 pvargDest->
vt = pvargSrc->
vt;
460 for (i = 0; i < cElements; i++) {
469 switch (pvargSrc->
vt) {
485 memcpy(pvargDest, pvargSrc,
sizeof(
VARIANT));
533 tmVal = gmtime(&pvarg->
date);
575 char *chRet, *chStr = NULL;
601 vntTmp.lVal = (
int32_t) wcstol(bstr, &wchRet, 0);
602 if ((wchRet == NULL) || ((*wchRet != L
'.') && (*wchRet != L
'\0'))) {
605 else if (errno == ERANGE) {
615 vntTmp.llVal = (
int64_t) wcstoll(bstr, &wchRet, 0);
616 if ((wchRet == NULL) || ((*wchRet != L
'.') && (*wchRet != L
'\0'))) {
619 else if (errno == ERANGE) {
625 vntTmp.fltVal = wcstof(bstr, &wchRet);
626 if ((wchRet == NULL) || (*wchRet != L
'\0')) {
629 else if (errno == ERANGE) {
635 vntTmp.dblVal = wcstod(bstr, &wchRet);
636 if ((wchRet == NULL) || (*wchRet != L
'\0')) {
639 else if (errno == ERANGE) {
645 vntTmp.cyVal.int64 = (
int64_t) wcstoll(bstr, &wchRet, 0);
646 if ((wchRet == NULL) || ((*wchRet != L
'.') && (*wchRet != L
'\0'))) {
649 else if (errno == ERANGE) {
657 vntTmp.ulVal = (
uint32_t) wcstoul(bstr, &wchRet, 0);
658 if ((wchRet == NULL) || ((*wchRet != L
'.') && (*wchRet != L
'\0'))) {
661 else if (errno == ERANGE) {
668 else if (*bstr == L
'-') {
674 vntTmp.ullVal = (
uint64_t) wcstoull(bstr, &wchRet, 0);
675 if ((wchRet == NULL) || ((*wchRet != L
'.') && (*wchRet != L
'\0'))) {
678 else if (errno == ERANGE) {
681 else if (*bstr == L
'-') {
686 len = wcstombs(NULL, bstr, 0) + 1;
692 chStr = (
char *) malloc(len);
698 wcstombs(chStr, bstr, len);
699 memset(&tmVal, 0,
sizeof(
struct tm));
701 if ((chRet == NULL) || (*chRet !=
'\0')) {
704 vntTmp.date = mktime(&tmVal);
741 if ((pvargDest == NULL) || (pvarSrc == NULL)) {
745 if (pvargDest != pvarSrc) {
747 if (vt == pvarSrc->
vt) {
751 if (vt == pvarSrc->
vt) {
756 #define CheckOverflow(typeDst, typeSrc) \ 757 ((sizeof(typeDst) < sizeof(typeSrc)) \ 758 || (pvarSrc->vt == VT_R4) \ 759 || (pvarSrc->vt == VT_R8)) 762 ((pvarSrc->vt == VT_UI1) \ 763 || (pvarSrc->vt == VT_UI2) \ 764 || (pvarSrc->vt == VT_UI4) \ 765 || (pvarSrc->vt == VT_UI8)) 767 #define SubChangeType(type, val, chk) \ 771 memset(pvargDest, 0, sizeof(VARIANT)); \ 774 return DISP_E_TYPEMISMATCH; \ 777 if(chk) { if(CheckOverflow(int16_t, type) \ 778 && ((!IsUnsigned && ((val) < (type)SHRT_MIN)) \ 779 || ((type)SHRT_MAX < (val)))) { \ 780 return DISP_E_OVERFLOW; \ 782 pvargDest->iVal = (int16_t)(val); \ 785 if(chk) { if(CheckOverflow(int32_t, type) \ 786 && ((!IsUnsigned && ((val) < (type)LONG_MIN)) \ 787 || ((type)LONG_MAX < (val)))) { \ 788 return DISP_E_OVERFLOW; \ 790 pvargDest->lVal = (int32_t)(val); \ 793 if(chk) { if(CheckOverflow(int64_t, type) \ 794 && ((!IsUnsigned && ((val) < (type)LLONG_MIN)) \ 795 || ((type)LLONG_MAX < (val)))) { \ 796 return DISP_E_OVERFLOW; \ 798 pvargDest->llVal = (int64_t)(val); \ 801 if(chk) { if((pvarSrc->vt == VT_R8) \ 802 && (((val) < (double)-FLT_MAX) \ 803 || ((double)FLT_MAX < (val)))) { \ 804 return DISP_E_OVERFLOW; \ 806 pvargDest->fltVal = (float)(val); \ 809 pvargDest->dblVal = (double)(val); \ 812 if(chk) { if(CheckOverflow(int64_t, type) \ 813 && ((!IsUnsigned && ((val) < (type)LLONG_MIN)) \ 814 || ((type)LLONG_MAX < (val)))) { \ 815 return DISP_E_OVERFLOW; \ 817 pvargDest->cyVal.int64 = (int64_t)(val); \ 820 pvargDest->date = (DATE)(val); \ 823 hr = Variant2Bstr(&pvargDest->bstrVal, pvarSrc); \ 826 pvargDest->boolVal = ((val) ? VARIANT_TRUE : VARIANT_FALSE); \ 829 if(chk) { if(((val) < (type)0) || \ 830 (CheckOverflow(uint8_t, type) && ((type)USHRT_MAX < (val)))) { \ 831 return DISP_E_OVERFLOW; \ 833 pvargDest->bVal = (uint8_t)(val); \ 836 if(chk) { if(((pvarSrc->vt != VT_I2) && ((val) < (type)0)) || \ 837 (CheckOverflow(uint16_t, type) && ((type)USHRT_MAX < (val)))) { \ 838 return DISP_E_OVERFLOW; \ 840 pvargDest->uiVal = (uint16_t)(val); \ 843 if(chk) { if(((pvarSrc->vt != VT_I4) && ((val) < (type)0)) || \ 844 (CheckOverflow(uint32_t, type) && ((type)ULONG_MAX < (val)))) { \ 845 return DISP_E_OVERFLOW; \ 847 pvargDest->ulVal = (uint32_t)(val); \ 850 if(chk) { if(((pvarSrc->vt != VT_I8) && ((val) < (type)0)) || \ 851 (CheckOverflow(uint64_t, type) && ((type)ULLONG_MAX < (val)))) { \ 852 return DISP_E_OVERFLOW; \ 854 pvargDest->ullVal = (uint64_t)(val); \ 857 return DISP_E_BADVARTYPE; \ 860 switch (pvarSrc->
vt) {
869 memset(pvargDest, 0,
sizeof(
VARIANT));
886 SubChangeType(
float, pvarSrc->
fltVal, 1);
889 SubChangeType(
double, pvarSrc->
dblVal, 1);
895 SubChangeType(
DATE, pvarSrc->
date, 1);
898 hr = Bstr2Variant(pvargDest, vt, pvarSrc->
bstrVal);
928 #if (_DN_USE_VARIANT_API) 944 if ((pDest == NULL) || (dwSize == 0)) {
953 void *pVal, *pPos = pDest;
956 for (i = 0; i < lMax; i++) {
973 vntTmp.
fltVal = *((
float *) pVal + i);
977 vntTmp.
dblVal = *((
double *) pVal + i);
981 vntTmp.
cyVal = *((
CY *) pVal + i);
1043 if (dwCnt >= dwSize) {
1070 *(
float *) pDest = vntTmp.
fltVal;
1073 *(
double *) pDest = vntTmp.
dblVal;
1126 int iLevelCount = 0, bGetTitle = 0;
1128 uint16_t i, uiLenTarget = 0, uiLenOptTitle = 0, uiLenOneOpt = 0;
1129 wchar_t *wchTmp, *wchPos, wchStart = -1, wchEnd = -1;
1130 BSTR bstrTmp, bstrTarget, bstrOptTitle, bstrOneOpt;
1133 if ((bstrKey == NULL) || (pvarDest == NULL)) {
1137 if (bstrSrc != NULL) {
1147 wchTmp = bstrTarget;
1149 for (i = 0; i <= uiLenTarget; i++, wchTmp++) {
1179 if (*wchTmp == wchStart) {
1181 if (iLevelCount == 1) {
1182 memcpy(wchTmp, wchTmp + 1,
sizeof(
wchar_t) * (uiLenTarget - i));
1189 else if (*wchTmp == wchEnd) {
1192 if (iLevelCount < 0) {
1198 memcpy(wchTmp, wchTmp + 1,
sizeof(
wchar_t) * (uiLenTarget - i));
1208 if (*wchTmp == L
'=') {
1214 if (uiLenOptTitle > 0) {
1225 if (*wchTmp == L
',' || *wchTmp == L
'\0') {
1226 if (uiLenOneOpt > 0) {
1233 bstrTmp = bstrOptTitle;
1235 while (wchPos[0] == L
' ') {
1239 lTitleTerm = wcslen(wchPos) - 1;
1240 while (wchPos[lTitleTerm] == L
' ') {
1241 wchPos[lTitleTerm] = L
'\0';
1248 if (!_wcsicmp(bstrOptTitle, bstrKey)) {
1262 if (*wchTmp == L
',') {
1288 if (iLevelCount != 0) {
1293 bstrTmp = bstrOneOpt;
1295 while (wchPos[0] == L
' ') {
1299 lTitleTerm = wcslen(wchPos) - 1;
1300 while (wchPos[lTitleTerm] == L
' ') {
1301 wchPos[lTitleTerm] = L
'\0';
1321 #if (_DN_USE_BSTR_API) 1330 wchar_t* chDest = NULL;
1334 int iLen = MultiByteToWideChar(CP_ACP, 0, chSrc, -1, NULL, 0);
1336 chDest = (
wchar_t*)malloc(
sizeof(
wchar_t)*iLen);
1337 if(chDest == NULL)
return NULL;
1338 MultiByteToWideChar(CP_ACP, 0, chSrc, -1, chDest, iLen);
1341 char* locale = setlocale(LC_ALL, setlocale(LC_CTYPE,
""));
1342 int iLen = mbstowcs(NULL, chSrc, 0) + 1;
1344 chDest = (
wchar_t*)malloc(
sizeof(
wchar_t)*iLen);
1345 if(chDest == NULL)
return NULL;
1346 mbstowcs(chDest, chSrc, iLen);
1348 setlocale(LC_ALL, locale);
1363 char* chDest = NULL;
1367 int iLen = WideCharToMultiByte(CP_ACP, 0, chSrc, -1, NULL, 0, NULL, NULL);
1369 chDest = (
char*)malloc(iLen);
1370 if(chDest == NULL)
return NULL;
1371 WideCharToMultiByte(CP_ACP, 0, chSrc, -1, chDest, iLen, NULL, NULL);
1374 char* locale = setlocale(LC_ALL, setlocale(LC_CTYPE,
""));
1375 int iLen = wcstombs(NULL, chSrc, 0) + 1;
1377 chDest = (
char*)malloc(iLen);
1378 if(chDest == NULL)
return NULL;
1379 wcstombs(chDest, chSrc, iLen);
1381 setlocale(LC_ALL, locale);
void SysFreeString(BSTR bstr)
Releases the memory of BSTR.
HRESULT SafeArrayUnaccessData(SAFEARRAY *psa)
Unaccesses the SAFEARRAY.
BSTR SysAllocStringLen(const wchar_t *pch, uint16_t cch)
Allocates and returns BSTR.
uint16_t SafeArrayGetDim(SAFEARRAY *psa)
Gets and returns the dimension of SAFEARRAY.
SAFEARRAY * SafeArrayCreateVector(uint16_t vt, int32_t lLbound, uint32_t cElements)
Allocates and returns SAFEARRAY.
#define VARIANT_TRUE
TRUE for VARIANT.
_DN_EXP_COMMON uint32_t ChangeVarType(VARIANT varSrc, uint16_t vt, void *pDest, uint32_t dwSize)
Changes the variant to destination value with the indicated type.
HRESULT SafeArrayGetUBound(SAFEARRAY *psa, uint16_t nDim, int32_t *plUbound)
Gets the upper bound of SAFEARRAY.
HRESULT SafeArrayGetVartype(SAFEARRAY *psa, uint16_t *pvt)
Gets the variant type of SAFEARRAY.
#define DISP_E_BADINDEX
Failed because the index is invalid.
#define FAILED(hr)
A macro that returns TRUE/FALSE. If hr is less than zero, then returns TRUE.
A type definition for the signed 64bit integer.
void VariantClear(VARIANT *pvarg)
Clears the VARIANT.
uint16_t SysStringLen(BSTR bstr)
Gets and returns the number of characters of BSTR.
uint32_t SafeArrayGetElemsize(SAFEARRAY *psa)
Gets and returns the size of an element.
#define DISP_E_BADVARTYPE
Failed because bad variable type.
#define E_INVALIDARG
Failed because some arguments are invalid.
void VariantInit(VARIANT *pvarg)
Initializes the VARIANT.
#define E_FAIL
Failed because unspecified error occurs.
unsigned long long uint64_t
BSTR SysAllocString(const wchar_t *sz)
Allocates and returns BSTR.
_DN_EXP_COMMON HRESULT VariantCopy(VARIANT *pvargDest, const VARIANT *pvargSrc)
Copies the source variant to destination variant.
A type definition for the array.
#define E_OUTOFMEMORY
Failed because there is no enough memory space.
#define DISP_E_OVERFLOW
Failed because out of range.
HRESULT SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Accesses the SAFEARRAY and gets the pointer of array data.
#define _LEN_VARIANT2BSTR
A definition for the string length for converting VARIANT to BSTR.
#define SUCCEEDED(hr)
A macro that returns TRUE/FALSE. If hr is zero or more, then returns TRUE.
_DN_EXP_COMMON HRESULT VariantChangeType(VARIANT *pvargDest, VARIANT *pvarSrc, uint16_t wFlags, uint16_t vt)
Changes the source variant to destination variant with the indicated type.
#define FORMAT_DATE2BSTR
A definition for the format string converting DATE to BSTR.
A type definition for the multi type variable.
#define VARIANT_FALSE
FALSE for VARIANT.
_DN_EXP_COMMON HRESULT GetOptionValue(BSTR bstrSrc, BSTR bstrKey, uint16_t vt, VARIANT *pvarDest)
Searchs the key string from source string and sets the value to the destination variant with the indi...
SAFEARRAYBOUND rgsabound[1]
HRESULT SafeArrayGetLBound(SAFEARRAY *psa, uint16_t nDim, int32_t *plLbound)
Gets the lower bound of SAFEARRAY.
#define DISP_E_TYPEMISMATCH
Failed because the type mismatch.
_DN_EXP_COMMON char * ConvertWideChar2MultiByte(const wchar_t *chSrc)
Converts wide string to string.
HRESULT SafeArrayDestroy(SAFEARRAY *psa)
Releases the memory of SAFEARRAY.
_DN_EXP_COMMON wchar_t * ConvertMultiByte2WideChar(const char *chSrc)
Converts string to wide string.