Changeset 6944 for trunk/src/oleaut32/safearray.c
- Timestamp:
- Oct 3, 2001, 9:22:00 PM (24 years ago)
- File:
-
- 1 edited
-
trunk/src/oleaut32/safearray.c (modified) (57 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/oleaut32/safearray.c
r6711 r6944 8 8 */ 9 9 10 #ifdef __WIN32OS2__11 #define HAVE_FLOAT_H12 #define WINE_LARGE_INTEGER13 #include "oleaut32.h"14 #endif15 10 #include <stdio.h> 16 11 #include <string.h> … … 24 19 DEFAULT_DEBUG_CHANNEL(ole); 25 20 21 #define SYSDUPSTRING(str) SysAllocStringLen((str), SysStringLen(str)) 22 26 23 /* Localy used methods */ 27 24 static INT … … 59 56 { 60 57 /* this is taken from wtypes.h. Only [S]es are supported by the SafeArray */ 61 VARTYPE_NOT_SUPPORTED, /* VT_EMPTY [V] [P] nothing */62 VARTYPE_NOT_SUPPORTED, /* VT_NULL [V] [P] SQL style Nul */63 2, /* VT_I2 [V][T][P][S] 2 byte signed int */64 4, /* VT_I4 [V][T][P][S] 4 byte signed int */65 4, /* VT_R4 [V][T][P][S] 4 byte real */66 8, /* VT_R8 [V][T][P][S] 8 byte real */58 VARTYPE_NOT_SUPPORTED, /* VT_EMPTY [V] [P] nothing */ 59 VARTYPE_NOT_SUPPORTED, /* VT_NULL [V] [P] SQL style Nul */ 60 2, /* VT_I2 [V][T][P][S] 2 byte signed int */ 61 4, /* VT_I4 [V][T][P][S] 4 byte signed int */ 62 4, /* VT_R4 [V][T][P][S] 4 byte real */ 63 8, /* VT_R8 [V][T][P][S] 8 byte real */ 67 64 8, /* VT_CY [V][T][P][S] currency */ 68 8, /* VT_DATE [V][T][P][S] date */69 4,/* VT_BSTR [V][T][P][S] OLE Automation string*/70 4,/* VT_DISPATCH [V][T][P][S] IDispatch * */65 8, /* VT_DATE [V][T][P][S] date */ 66 sizeof(BSTR), /* VT_BSTR [V][T][P][S] OLE Automation string*/ 67 sizeof(LPDISPATCH), /* VT_DISPATCH [V][T][P][S] IDispatch * */ 71 68 4, /* VT_ERROR [V][T] [S] SCODE */ 72 4, /* VT_BOOL [V][T][P][S] True=-1, False=0*/73 24,/* VT_VARIANT [V][T][P][S] VARIANT * */74 4,/* VT_UNKNOWN [V][T] [S] IUnknown * */75 16,/* VT_DECIMAL [V][T] [S] 16 byte fixed point */69 4, /* VT_BOOL [V][T][P][S] True=-1, False=0*/ 70 sizeof(VARIANT), /* VT_VARIANT [V][T][P][S] VARIANT * */ 71 sizeof(LPUNKNOWN), /* VT_UNKNOWN [V][T] [S] IUnknown * */ 72 sizeof(DECIMAL), /* VT_DECIMAL [V][T] [S] 16 byte fixed point */ 76 73 VARTYPE_NOT_SUPPORTED, /* no VARTYPE here..... */ 77 74 VARTYPE_NOT_SUPPORTED, /* VT_I1 [T] signed char */ 78 1, /* VT_UI1 [V][T][P][S] unsigned char */75 1, /* VT_UI1 [V][T][P][S] unsigned char */ 79 76 VARTYPE_NOT_SUPPORTED, /* VT_UI2 [T][P] unsigned short */ 80 77 VARTYPE_NOT_SUPPORTED, /* VT_UI4 [T][P] unsigned short */ … … 109 106 110 107 /************************************************************************* 111 * SafeArrayAllocDescriptor 108 * SafeArrayAllocDescriptor (OLEAUT32.36) 112 109 * Allocate the appropriate amount of memory for the SafeArray descriptor 113 110 */ … … 134 131 135 132 /************************************************************************* 136 * SafeArrayAllocData 133 * SafeArrayAllocData (OLEAUT32.37) 137 134 * Allocate the appropriate amount of data for the SafeArray data 138 135 */ … … 141 138 { 142 139 ULONG ulWholeArraySize; /* to store the size of the whole thing */ 143 144 dprintf(("SafeArrayAllocData %x", psa));145 140 146 141 if(! validArg(psa)) … … 161 156 162 157 /************************************************************************* 163 * SafeArrayCreate 158 * SafeArrayCreate (OLEAUT32.15) 164 159 * Create a SafeArray object by encapsulating AllocDescriptor and AllocData 165 160 */ … … 172 167 HRESULT hRes; 173 168 USHORT cDim; 174 175 dprintf(("SafeArrayCreate %x %d %x", vt, cDims, rgsabound));176 169 177 170 /* Validate supported VARTYPE */ … … 208 201 209 202 /************************************************************************* 210 * SafeArrayDestroyDescriptor 203 * SafeArrayDestroyDescriptor (OLEAUT32.38) 211 204 * Frees the memory associated with the descriptor. 212 205 */ … … 214 207 SAFEARRAY *psa) 215 208 { 216 dprintf(("SafeArrayDestroyDescriptor %x", psa));217 218 209 /* Check for lockness before to free... */ 219 210 if(psa->cLocks > 0) … … 229 220 230 221 /************************************************************************* 231 * SafeArrayLock 222 * SafeArrayLock (OLEAUT32.21) 232 223 * Increment the lock counter 233 224 * … … 239 230 SAFEARRAY *psa) 240 231 { 241 dprintf(("SafeArrayLock %x", psa));242 243 232 if(! validArg(psa)) 244 233 return E_INVALIDARG; … … 250 239 251 240 /************************************************************************* 252 * SafeArrayUnlock 241 * SafeArrayUnlock (OLEAUT32.22) 253 242 * Decrement the lock counter 254 243 */ … … 256 245 SAFEARRAY *psa) 257 246 { 258 dprintf(("SafeArrayUnlock %x", psa));259 260 247 if(! validArg(psa)) 261 248 return E_INVALIDARG; … … 269 256 270 257 /************************************************************************* 271 * SafeArrayPutElement 258 * SafeArrayPutElement (OLEAUT32.26) 272 259 * Set the data at the given coordinate 273 260 */ … … 280 267 the desired one... */ 281 268 PVOID elementStorageAddress = NULL; /* Adress to store the data */ 282 BSTR pbstrReAllocStr = NULL; /* BSTR reallocated */283 284 dprintf(("SafeArrayPutElement %x %x %x", psa, rgIndices, pv));285 269 286 270 /* Validate the index given */ … … 300 284 if(isPointer(psa->fFeatures)) { /* increment ref count for this pointer */ 301 285 302 *(( VOID**)elementStorageAddress) = *(VOID**)pv;286 *((PVOID*)elementStorageAddress) = *(PVOID*)pv; 303 287 IUnknown_AddRef( *(IUnknown**)pv); 304 288 … … 306 290 307 291 if(psa->fFeatures == FADF_BSTR) { /* Create a new object */ 308 309 if((pbstrReAllocStr = SysAllocString( (OLECHAR*)pv )) == NULL) { 292 BSTR pbstrReAllocStr = NULL; 293 if(pv && 294 ((pbstrReAllocStr = SYSDUPSTRING( (OLECHAR*)pv )) == NULL)) { 310 295 SafeArrayUnlock(psa); 311 296 return E_OUTOFMEMORY; 312 297 } else 313 298 *((BSTR*)elementStorageAddress) = pbstrReAllocStr; 314 315 } else /* dupplicate the memory */ 299 } 300 else if(psa->fFeatures == FADF_VARIANT) { 301 HRESULT hr = VariantCopy(elementStorageAddress, pv); 302 if (FAILED(hr)) { 303 SafeArrayUnlock(psa); 304 return hr; 305 } 306 } 307 else /* duplicate the memory */ 316 308 memcpy(elementStorageAddress, pv, SafeArrayGetElemsize(psa) ); 317 309 } … … 328 320 329 321 /************************************************************************* 330 * SafeArrayGetElement 322 * SafeArrayGetElement (OLEAUT32.25) 331 323 * Return the data element corresponding the the given coordinate 332 324 */ … … 339 331 the desired one... */ 340 332 PVOID elementStorageAddress = NULL; /* Adress to store the data */ 341 BSTR pbstrReturnedStr = NULL; /* BSTR reallocated */342 343 dprintf(("SafeArrayGetElement %x %x %x", psa, rgIndices, pv));344 333 345 334 if(! validArg(psa)) … … 358 347 359 348 if( psa->fFeatures == FADF_BSTR) { /* reallocate the obj */ 360 if( (pbstrReturnedStr = 361 SysAllocString( *(OLECHAR**)elementStorageAddress )) == NULL) { 349 BSTR pbstrStoredStr = *(OLECHAR**)elementStorageAddress; 350 BSTR pbstrReturnedStr = NULL; 351 if( pbstrStoredStr && 352 ((pbstrReturnedStr = SYSDUPSTRING( pbstrStoredStr )) == NULL) ) { 362 353 SafeArrayUnlock(psa); 363 354 return E_OUTOFMEMORY; 364 355 } else 365 356 *((BSTR*)pv) = pbstrReturnedStr; 366 367 } else if( isPointer(psa->fFeatures) ) /* simply copy the pointer */ 368 pv = *((PVOID*)elementStorageAddress); 357 } 358 else if( psa->fFeatures == FADF_VARIANT) { 359 HRESULT hr = VariantCopy(pv, elementStorageAddress); 360 if (FAILED(hr)) { 361 SafeArrayUnlock(psa); 362 return hr; 363 } 364 } 365 else if( isPointer(psa->fFeatures) ) /* simply copy the pointer */ 366 *(PVOID*)pv = *((PVOID*)elementStorageAddress); 369 367 else /* copy the bytes */ 370 memcpy(pv, elementStorageAddress, SafeArrayGetElemsize(psa));368 memcpy(pv, elementStorageAddress, psa->cbElements ); 371 369 372 370 } else { … … 379 377 380 378 /************************************************************************* 381 * SafeArrayGetUBound 379 * SafeArrayGetUBound (OLEAUT32.19) 382 380 * return the UP bound for a given array dimension 383 381 */ … … 387 385 LONG *plUbound) 388 386 { 389 390 dprintf(("SafeArrayGetUBound %x %x %x", psa, nDim, plUbound));391 392 387 if(! validArg(psa)) 393 388 return E_INVALIDARG; … … 396 391 return DISP_E_BADINDEX; 397 392 393 if(0 == nDim) 394 return DISP_E_BADINDEX; 395 398 396 *plUbound = psa->rgsabound[nDim-1].lLbound + 399 397 psa->rgsabound[nDim-1].cElements - 1; … … 403 401 404 402 /************************************************************************* 405 * SafeArrayGetLBound 403 * SafeArrayGetLBound (OLEAUT32.20) 406 404 * Return the LO bound for a given array dimension 407 405 */ … … 417 415 return DISP_E_BADINDEX; 418 416 417 if(0 == nDim) 418 return DISP_E_BADINDEX; 419 419 420 *plLbound = psa->rgsabound[nDim-1].lLbound; 420 421 return S_OK; … … 422 423 423 424 /************************************************************************* 424 * SafeArrayGetDim 425 * SafeArrayGetDim (OLEAUT32.17) 425 426 * returns the number of dimension in the array 426 427 */ … … 439 440 440 441 /************************************************************************* 441 * SafeArrayGetElemsize 442 * SafeArrayGetElemsize (OLEAUT32.18) 442 443 * Return the size of the element in the array 443 444 */ … … 456 457 457 458 /************************************************************************* 458 * SafeArrayAccessData 459 * SafeArrayAccessData (OLEAUT32.23) 459 460 * increment the access count and return the data 460 461 */ … … 484 485 485 486 /************************************************************************* 486 * SafeArrayUnaccessData 487 * SafeArrayUnaccessData (OLEAUT32.24) 487 488 * Decrement the access count 488 489 */ … … 497 498 498 499 /************************************************************************ 499 * SafeArrayPtrOfIndex 500 * SafeArrayPtrOfIndex (OLEAUT32.148) 500 501 * Return a pointer to the element at rgIndices 501 502 */ … … 523 524 524 525 /************************************************************************ 525 * SafeArrayDestroyData 526 * SafeArrayDestroyData (OLEAUT32.39) 526 527 * Frees the memory data bloc 527 528 */ … … 532 533 ULONG ulWholeArraySize; /* count spot in array */ 533 534 ULONG ulDataIter; /* to iterate the data space */ 534 IUnknown *punk;535 BSTR bstr;536 535 537 536 if(! validArg(psa)) … … 544 543 545 544 if(isPointer(psa->fFeatures)) { /* release the pointers */ 545 IUnknown *punk; 546 546 547 547 for(ulDataIter=0; ulDataIter < ulWholeArraySize; ulDataIter++) { … … 552 552 } 553 553 554 } else if(psa->fFeatures & FADF_BSTR) { /* deallocate the obj */ 554 } 555 else if(psa->fFeatures & FADF_BSTR) { /* deallocate the obj */ 556 BSTR bstr; 555 557 556 558 for(ulDataIter=0; ulDataIter < ulWholeArraySize; ulDataIter++) { … … 559 561 if( bstr != NULL) 560 562 SysFreeString( bstr ); 563 } 564 } 565 else if(psa->fFeatures & FADF_VARIANT) { /* deallocate the obj */ 566 567 for(ulDataIter=0; ulDataIter < ulWholeArraySize; ulDataIter++) { 568 VariantClear((VARIANT*)((char *) psa->pvData+(ulDataIter*(psa->cbElements)))); 561 569 } 562 570 } … … 578 586 579 587 /************************************************************************ 580 * SafeArrayCopyData 588 * SafeArrayCopyData (OLEAUT32.412) 581 589 * Copy the psaSource's data block into psaTarget if dimension and size 582 590 * permits it. … … 616 624 } 617 625 618 } else if( (*psaTarget)->fFeatures & FADF_BSTR) { /* the target contain BSTR 626 } 627 else if( (*psaTarget)->fFeatures & FADF_BSTR) { /* the target contain BSTR 619 628 that must be freed */ 620 629 for(lDelta=0;lDelta < ulWholeArraySize; lDelta++) { … … 626 635 } 627 636 } 637 else if( (*psaTarget)->fFeatures & FADF_VARIANT) { 638 639 for(lDelta=0;lDelta < ulWholeArraySize; lDelta++) { 640 VariantClear((VARIANT*)((char *) (*psaTarget)->pvData + (lDelta * (*psaTarget)->cbElements))); 641 } 642 } 628 643 629 644 return duplicateData(psaSource, psaTarget); … … 631 646 632 647 /************************************************************************ 633 * SafeArrayDestroy 648 * SafeArrayDestroy (OLEAUT32.16) 634 649 * Deallocates all memory reserved for the SafeArray 635 650 */ … … 653 668 654 669 /************************************************************************ 655 * SafeArrayCopy 670 * SafeArrayCopy (OLEAUT32.27) 656 671 * Make a dupplicate of a SafeArray 657 672 */ … … 706 721 707 722 /************************************************************************ 708 * SafeArrayCreateVector 723 * SafeArrayCreateVector (OLEAUT32.411) 709 724 * Creates a one dimension safearray where the data is next to the 710 725 * SAFEARRAY structure. … … 743 758 744 759 /************************************************************************ 745 * SafeArrayRedim 760 * SafeArrayRedim (OLEAUT32.40) 746 761 * Changes the caracteristics of the last dimension of the SafeArray 747 762 */ … … 808 823 /* Check whether the size of the chunk makes sense... That's the only thing 809 824 I can think of now... */ 825 810 826 psaSize = HeapSize(GetProcessHeap(), 0, psa); 811 827 if (psaSize == -1) … … 838 854 if(lDelta < 0) { /* array needs to be shorthen */ 839 855 if( isPointer(psa->fFeatures)) /* ptr that need to be released */ 840 for(;lDelta < 0; lDelta++) {856 for(;lDelta < 0; lDelta++) { 841 857 punk = *(IUnknown**) 842 858 ((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements)); … … 847 863 848 864 else if(psa->fFeatures & FADF_BSTR) /* BSTR that need to be freed */ 849 for(;lDelta < 0; lDelta++) {865 for(;lDelta < 0; lDelta++) { 850 866 bstr = *(BSTR*) 851 867 ((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements)); … … 853 869 if( bstr != NULL ) 854 870 SysFreeString( bstr ); 871 } 872 else if(psa->fFeatures & FADF_VARIANT) 873 for(;lDelta < 0; lDelta++) { 874 VariantClear((VARIANT*)((char *) psa->pvData+((ulWholeArraySize+lDelta)*psa->cbElements))); 855 875 } 856 876 } … … 894 914 { 895 915 switch(vt) { 916 case VT_BSTR: return FADF_BSTR; 896 917 case VT_UNKNOWN: return FADF_UNKNOWN; 897 918 case VT_DISPATCH: return FADF_DISPATCH; 898 case VT_ BSTR: return FADF_BSTR;919 case VT_VARIANT: return FADF_VARIANT; 899 920 } 900 921 return 0; … … 973 994 974 995 for(; iter<psa->cDims; iter++) { 975 if((hRes = SafeArrayGetLBound(psa, iter, &lLBound)) != S_OK)996 if((hRes = SafeArrayGetLBound(psa, (iter+1), &lLBound)) != S_OK) 976 997 return FALSE; 977 if((hRes = SafeArrayGetUBound(psa, iter, &lUBound)) != S_OK)998 if((hRes = SafeArrayGetUBound(psa, (iter+1), &lUBound)) != S_OK) 978 999 return FALSE; 979 1000 … … 1014 1035 ULONG ulWholeArraySize; /* size of the thing */ 1015 1036 LONG lDelta; 1016 IUnknown *punk;1017 BSTR pbstrReAllocStr = NULL; /* BSTR reallocated */1018 1037 1019 1038 ulWholeArraySize = getArraySize(psa); /* Number of item in SA */ … … 1023 1042 if( isPointer(psa->fFeatures) ) { /* If datatype is object increment 1024 1043 object's reference count */ 1044 IUnknown *punk; 1025 1045 1026 1046 for(lDelta=0; lDelta < ulWholeArraySize; lDelta++) { … … 1035 1055 ulWholeArraySize*psa->cbElements); 1036 1056 1037 } else if( psa->fFeatures & FADF_BSTR ) { /* if datatype is BSTR allocate 1038 the BSTR in the new array */ 1057 } 1058 else if( psa->fFeatures & FADF_BSTR ) { /* if datatype is BSTR allocate 1059 the BSTR in the new array */ 1060 BSTR pbstrReAllocStr = NULL; 1039 1061 1040 1062 for(lDelta=0; lDelta < ulWholeArraySize; lDelta++) { 1041 if(( pbstrReAllocStr = S ysAllocString(1063 if(( pbstrReAllocStr = SYSDUPSTRING( 1042 1064 *(BSTR*)((char *) psa->pvData+(lDelta * psa->cbElements)))) == NULL) { 1043 1065 … … 1050 1072 } 1051 1073 1052 } else { /* Simply copy the source array data into target array */ 1074 } 1075 else if( psa->fFeatures & FADF_VARIANT ) { 1076 1077 for(lDelta=0; lDelta < ulWholeArraySize; lDelta++) { 1078 VariantCopy((VARIANT*)((char *) (*ppsaOut)->pvData+(lDelta * psa->cbElements)), 1079 (VARIANT*)((char *) psa->pvData+(lDelta * psa->cbElements))); 1080 } 1081 1082 } 1083 else { /* Simply copy the source array data into target array */ 1053 1084 1054 1085 memcpy((*ppsaOut)->pvData, psa->pvData, … … 1063 1094 1064 1095 /************************************************************************ 1065 * SafeArrayGetVarType 1096 * SafeArrayGetVarType (OLEAUT32.77) 1066 1097 * Returns the VARTYPE stored in the given safearray 1067 1098 */ … … 1078 1109 { 1079 1110 /* VT tag @ negative offset 4 in the array descriptor */ 1080 FIXME("Returning VT_BSTR instead of VT_... ");1111 FIXME("Returning VT_BSTR instead of VT_...\n"); 1081 1112 vt = VT_BSTR; 1082 1113 } … … 1085 1116 vt = VT_RECORD; 1086 1117 } 1118 else if (psa->fFeatures & FADF_BSTR) 1119 { 1120 vt = VT_BSTR; 1121 } 1122 else if (psa->fFeatures & FADF_UNKNOWN) 1123 { 1124 vt = VT_UNKNOWN; 1125 } 1087 1126 else if (psa->fFeatures & FADF_DISPATCH) 1088 1127 { 1089 1128 vt = VT_DISPATCH; 1090 1129 } 1091 else if (psa->fFeatures & FADF_ UNKNOWN)1130 else if (psa->fFeatures & FADF_VARIANT) 1092 1131 { 1093 vt = VT_ UNKNOWN;1132 vt = VT_VARIANT; 1094 1133 } 1095 1134 … … 1099 1138 hr = S_OK; 1100 1139 } 1101 1102 TRACE("HRESULT = %08lx ", hr);1140 1141 TRACE("HRESULT = %08lx\n", hr); 1103 1142 return hr; 1104 1143 }
Note:
See TracChangeset
for help on using the changeset viewer.
