Changeset 50930 in vbox for trunk/src/VBox
- Timestamp:
- Mar 31, 2014 3:55:14 PM (11 years ago)
- Location:
- trunk/src/VBox/Main/cbinding
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/cbinding/VBoxCAPI.cpp
r50183 r50930 232 232 ULONG cbElement = VBoxVTElemSize(vt); 233 233 if (!cbElement) 234 { 235 *ppv = NULL; 236 if (pcb) 237 *pcb = 0; 234 238 return E_INVALIDARG; 239 } 235 240 #ifndef VBOX_WITH_XPCOM 236 241 if (psa->cDims != 1) 242 { 243 *ppv = NULL; 244 if (pcb) 245 *pcb = 0; 237 246 return E_INVALIDARG; 247 } 238 248 Assert(cbElement = psa->cbElements); 239 249 #endif /* !VBOX_WITH_XPCOM */ … … 246 256 HRESULT rc = SafeArrayAccessData(psa, &pData); 247 257 if (FAILED(rc)) 248 return rc; 258 { 259 *ppv = NULL; 260 if (pcb) 261 *pcb = 0; 262 return rc; 263 } 249 264 cElements = psa->rgsabound[0].cElements; 250 265 #endif /* !VBOX_WITH_XPCOM */ 251 266 size_t cbTotal = cbElement * cElements; 252 void *pv = malloc(cbTotal); 253 if (pv) 254 { 255 memcpy(pv, pData, cbTotal); 256 *ppv = pv; 257 if (pcb) 258 *pcb = (ULONG)cbTotal; 259 } 267 void *pv = NULL; 268 if (cbTotal) 269 { 270 pv = malloc(cbTotal); 271 if (!pv) 272 { 273 *ppv = NULL; 274 if (pcb) 275 *pcb = 0; 276 return E_OUTOFMEMORY; 277 } 278 else 279 memcpy(pv, pData, cbTotal); 280 } 281 *ppv = pv; 282 if (pcb) 283 *pcb = (ULONG)cbTotal; 260 284 #ifndef VBOX_WITH_XPCOM 261 285 SafeArrayUnaccessData(psa); … … 270 294 HRESULT rc = VBoxSafeArrayCopyOutParamHelper((void **)ppaObj, &mypcb, VT_UNKNOWN, psa); 271 295 if (FAILED(rc)) 272 return rc; 296 { 297 if (pcObj) 298 *pcObj = 0; 299 return rc; 300 } 273 301 ULONG cElements = mypcb / sizeof(void *); 274 302 if (pcObj) … … 286 314 } 287 315 #endif /* VBOX_WITH_XPCOM */ 316 return S_OK; 317 } 318 319 static HRESULT 320 VBoxArrayOutFree(void *pv) 321 { 322 free(pv); 288 323 return S_OK; 289 324 } … … 715 750 VBoxSafeArrayCopyOutIfaceParamHelper, 716 751 VBoxSafeArrayDestroy, 752 VBoxArrayOutFree, 717 753 718 754 #ifdef VBOX_WITH_XPCOM … … 731 767 732 768 /* 733 * Legacy interface version 3.0.769 * Legacy interface version 4.0. 734 770 */ 735 static const struct VBOXCAPIV 3771 static const struct VBOXCAPIV4 736 772 { 737 773 /** The size of the structure. */ … … 741 777 742 778 unsigned int (*pfnGetVersion)(void); 743 744 779 unsigned int (*pfnGetAPIVersion)(void); 745 780 746 781 HRESULT (*pfnClientInitialize)(const char *pszVirtualBoxClientIID, 747 782 IVirtualBoxClient **ppVirtualBoxClient); 783 HRESULT (*pfnClientThreadInitialize)(void); 784 HRESULT (*pfnClientThreadUninitialize)(void); 748 785 void (*pfnClientUninitialize)(void); 749 786 … … 755 792 void (*pfnComUninitialize)(void); 756 793 757 void (*pfnComUnallocMem)(void *pv);794 void (*pfnComUnallocString)(BSTR pwsz); 758 795 759 796 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); … … 762 799 void (*pfnUtf16Free)(BSTR pwszString); 763 800 801 SAFEARRAY *(*pfnSafeArrayCreateVector)(VARTYPE vt, LONG lLbound, ULONG cElements); 802 SAFEARRAY *(*pfnSafeArrayOutParamAlloc)(void); 803 HRESULT (*pfnSafeArrayCopyInParamHelper)(SAFEARRAY *psa, const void *pv, ULONG cb); 804 HRESULT (*pfnSafeArrayCopyOutParamHelper)(void **ppv, ULONG *pcb, VARTYPE vt, SAFEARRAY *psa); 805 HRESULT (*pfnSafeArrayCopyOutIfaceParamHelper)(IUnknown ***ppaObj, ULONG *pcObj, SAFEARRAY *psa); 806 HRESULT (*pfnSafeArrayDestroy)(SAFEARRAY *psa); 807 764 808 #ifdef VBOX_WITH_XPCOM 765 809 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); … … 767 811 HRESULT (*pfnGetException)(IErrorInfo **ppException); 768 812 HRESULT (*pfnClearException)(void); 813 int (*pfnProcessEventQueue)(LONG64 iTimeoutMS); 814 int (*pfnInterruptEventQueueProcessing)(void); 769 815 770 816 /** Tail version, same as uVersion. */ 771 817 unsigned uEndVersion; 772 } s_Functions_v 3_0 =773 { 774 sizeof(s_Functions_v 3_0),775 0x000 30000U,818 } s_Functions_v4_0 = 819 { 820 sizeof(s_Functions_v4_0), 821 0x00040000U, 776 822 777 823 VBoxVersion, … … 779 825 780 826 VBoxClientInitialize, 827 VBoxClientThreadInitialize, 828 VBoxClientThreadUninitialize, 781 829 VBoxClientUninitialize, 782 830 … … 784 832 VBoxComUninitialize, 785 833 786 VBoxComUnalloc Mem,834 VBoxComUnallocString, 787 835 788 836 VBoxUtf16ToUtf8, … … 791 839 VBoxUtf16Free, 792 840 841 VBoxSafeArrayCreateVector, 842 VBoxSafeArrayOutParamAlloc, 843 VBoxSafeArrayCopyInParamHelper, 844 VBoxSafeArrayCopyOutParamHelper, 845 VBoxSafeArrayCopyOutIfaceParamHelper, 846 VBoxSafeArrayDestroy, 847 848 #ifdef VBOX_WITH_XPCOM 849 VBoxGetEventQueue, 850 #endif /* VBOX_WITH_XPCOM */ 851 VBoxGetException, 852 VBoxClearException, 853 VBoxProcessEventQueue, 854 VBoxInterruptEventQueueProcessing, 855 856 0x00040000U 857 }; 858 859 if ((uVersion & 0xffff0000U) == 0x00040000U) 860 return (PCVBOXCAPI)&s_Functions_v4_0; 861 862 /* 863 * Legacy interface version 3.0. 864 */ 865 static const struct VBOXCAPIV3 866 { 867 /** The size of the structure. */ 868 unsigned cb; 869 /** The structure version. */ 870 unsigned uVersion; 871 872 unsigned int (*pfnGetVersion)(void); 873 874 unsigned int (*pfnGetAPIVersion)(void); 875 876 HRESULT (*pfnClientInitialize)(const char *pszVirtualBoxClientIID, 877 IVirtualBoxClient **ppVirtualBoxClient); 878 void (*pfnClientUninitialize)(void); 879 880 void (*pfnComInitialize)(const char *pszVirtualBoxIID, 881 IVirtualBox **ppVirtualBox, 882 const char *pszSessionIID, 883 ISession **ppSession); 884 885 void (*pfnComUninitialize)(void); 886 887 void (*pfnComUnallocMem)(void *pv); 888 889 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 890 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 891 void (*pfnUtf8Free)(char *pszString); 892 void (*pfnUtf16Free)(BSTR pwszString); 893 894 #ifdef VBOX_WITH_XPCOM 895 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); 896 #endif /* VBOX_WITH_XPCOM */ 897 HRESULT (*pfnGetException)(IErrorInfo **ppException); 898 HRESULT (*pfnClearException)(void); 899 900 /** Tail version, same as uVersion. */ 901 unsigned uEndVersion; 902 } s_Functions_v3_0 = 903 { 904 sizeof(s_Functions_v3_0), 905 0x00030000U, 906 907 VBoxVersion, 908 VBoxAPIVersion, 909 910 VBoxClientInitialize, 911 VBoxClientUninitialize, 912 913 VBoxComInitialize, 914 VBoxComUninitialize, 915 916 VBoxComUnallocMem, 917 918 VBoxUtf16ToUtf8, 919 VBoxUtf8ToUtf16, 920 VBoxUtf8Free, 921 VBoxUtf16Free, 922 793 923 #ifdef VBOX_WITH_XPCOM 794 924 VBoxGetEventQueue, -
trunk/src/VBox/Main/cbinding/capiidl.xsl
r50254 r50930 1358 1358 * owned by C bindings 1359 1359 */ 1360 void 1361 1362 1363 1360 void (*pfnComInitialize)(const char *pszVirtualBoxIID, 1361 IVirtualBox **ppVirtualBox, 1362 const char *pszSessionIID, 1363 ISession **ppSession); 1364 1364 /** 1365 1365 * Deprecated way to uninitialize the C bindings for an API client. … … 1373 1373 * @param pwsz pointer to string to be freed 1374 1374 */ 1375 void 1375 void (*pfnComUnallocString)(BSTR pwsz); 1376 1376 #ifndef WIN32 1377 1377 /** Legacy function, was always for freeing strings only. */ … … 1386 1386 * @returns IPRT status code 1387 1387 */ 1388 int 1388 int (*pfnUtf16ToUtf8)(CBSTR pwszString, char **ppszString); 1389 1389 /** 1390 1390 * Convert string from UTF-8 encoding to UTF-16 encoding. … … 1394 1394 * @returns IPRT status code 1395 1395 */ 1396 int 1396 int (*pfnUtf8ToUtf16)(const char *pszString, BSTR *ppwszString); 1397 1397 /** 1398 1398 * Free memory returned by pfnUtf16ToUtf8. Do not use for anything else. … … 1400 1400 * @param pszString string to be freed. 1401 1401 */ 1402 void 1402 void (*pfnUtf8Free)(char *pszString); 1403 1403 /** 1404 1404 * Free memory returned by pfnUtf8ToUtf16. Do not use for anything else. … … 1406 1406 * @param pwszString string to be freed. 1407 1407 */ 1408 void 1408 void (*pfnUtf16Free)(BSTR pwszString); 1409 1409 1410 1410 /** … … 1441 1441 * 1442 1442 * @param ppv output pointer to newly created array, which has to 1443 * be freed with free().1443 * be freed with pfnArrayOutFree. 1444 1444 * @param pcb number of bytes in the output buffer. 1445 1445 * @param vt variant type, defines the size of the elements … … 1452 1452 * 1453 1453 * @param ppaObj output pointer to newly created array, which has 1454 * to be freed with free(). Note that it's the caller's1454 * to be freed with pfnArrayOutFree. Note that it's the caller's 1455 1455 * responsibility to call Release() on each non-NULL interface 1456 1456 * pointer before freeing. … … 1463 1463 * Free a safearray 1464 1464 * 1465 * @param psa pointer to safearray for getting the data1465 * @param psa pointer to safearray 1466 1466 * @returns COM/XPCOM error code 1467 1467 */ 1468 1468 HRESULT (*pfnSafeArrayDestroy)(SAFEARRAY *psa); 1469 /** 1470 * Free an out array created by pfnSafeArrayCopyOutParamHelper or 1471 * pdnSafeArrayCopyOutIfaceParamHelper. 1472 * 1473 * @param psa pointer to memory block 1474 * @returns COM/XPCOM error code 1475 */ 1476 HRESULT (*pfnArrayOutFree)(void *pv); 1469 1477 1470 1478 #ifndef WIN32 … … 1475 1483 * owned by C bindings. 1476 1484 */ 1477 void 1485 void (*pfnGetEventQueue)(nsIEventQueue **ppEventQueue); 1478 1486 #endif /* !WIN32 */ 1479 1487 -
trunk/src/VBox/Main/cbinding/tstCAPIGlue.c
r50254 r50930 740 740 BSTR env = NULL; 741 741 BSTR sessionType; 742 SAFEARRAY *groupsSA = g_pVBoxFuncs->pfnSafeArrayOutParamAlloc(); 742 743 743 744 rc = IVirtualBox_FindMachine(virtualBox, id, &machine); … … 746 747 PrintErrorInfo(argv0, "Error: Couldn't get the Machine reference", rc); 747 748 return; 749 } 750 751 rc = IMachine_get_Groups(machine, ComSafeArrayAsOutParam(groupsSA)); 752 if (SUCCEEDED(rc)) 753 { 754 BSTR *groups = NULL; 755 ULONG cbGroups = 0; 756 ULONG i, cGroups; 757 g_pVBoxFuncs->pfnSafeArrayCopyOutParamHelper((void **)&groups, &cbGroups, VT_BSTR, groupsSA); 758 cGroups = cbGroups / sizeof(groups[0]); 759 for (i = 0; i < cGroups; ++i) 760 { 761 /* Note that the use of %S might be tempting, but it is not 762 * available on all platforms, and even where it is usable it 763 * may depend on correct compiler options to make wchar_t a 764 * 16 bit number. So better play safe and use UTF-8. */ 765 char *group; 766 g_pVBoxFuncs->pfnUtf16ToUtf8(groups[i], &group); 767 printf("Groups[%d]: %s\n", i, group); 768 g_pVBoxFuncs->pfnUtf8Free(group); 769 } 770 for (i = 0; i < cGroups; ++i) 771 g_pVBoxFuncs->pfnComUnallocString(groups[i]); 772 g_pVBoxFuncs->pfnArrayOutFree(groups); 748 773 } 749 774 … … 835 860 if (!machineCnt) 836 861 { 862 g_pVBoxFuncs->pfnArrayOutFree(machines); 837 863 printf("\tNo VMs\n"); 838 864 return; … … 962 988 } 963 989 } 964 if (machines) 965 free(machines); 990 g_pVBoxFuncs->pfnArrayOutFree(machines); 966 991 } 967 992
Note:
See TracChangeset
for help on using the changeset viewer.