标签:des style blog http color io os 使用 ar
在前一篇博文《读取SafeArray数据》我们介绍了C#读取安全数组;那么我们的COM怎么编写呢?
SAFEARRAY *pSArray = NULL;
SafeArrayDestroy(pSArray);
pSArray = SafeArrayCreateVector(VT_UI1, 0, 32);
Variable type is not specified.
Variable type is NULL.
Variable type is 2-byte signed INT.
Variable type is 4-byte signed INT.
Variable type is 4-byte real.
Variable type is 8-byte real.
Variable type is currency.
Variable type is date.
Variable type is binary string.
Variable type is IDispatch FAR*.
Variable type is SCODE.
Variable type is Boolean; True=-1, False=0.
Variable type is VARIANT FAR*.
Variable type is IUnknown FAR*.
Variable type is unsigned char.
This element is reserved.
Variable type is a pointer to data.
Variable type is a safe array.
SafeArrayPutElement(pSArray, &l, &inqReport[l]);
实例程序(COM方法):
AA:屏蔽的数值
STDMETHODIMP CRepoFmt::getInqRepo(ULONG iStation, SAFEARRAY** ret) { SAFEARRAY *pSArray = NULL; unsigned char inqReport[32]; unsigned char xorByte = AA; int iStationID = 0; if (iStation < 1) iStationID = 1; else iStationID = iStation; inqReport[0] = AA; inqReport[1] = AA; inqReport[2] = AA; inqReport[3] = AA; inqReport[4] = (iStationID % AA); inqReport[5] = (iStationID / AA); inqReport[6] = AA; inqReport[7] = AA; inqReport[8] = AA; inqReport[9] = AA; inqReport[10] = AA; inqReport[11] = AA; for (int i = 1; i < 18; i++) xorByte ^= inqReport[i]; inqReport[18] = xorByte; // Fill the inqReport etc. for (int j = 12; j < 18; j++) inqReport[j] = 0; for (int k = 19; k < 32; k++) inqReport[k] = 0; if (!ret) return E_POINTER; if (*ret) { SafeArrayDestroy(pSArray); *ret = NULL; } pSArray = SafeArrayCreateVector(VT_UI1, 0, 32); for (long l = 0; l < 32; l++) SafeArrayPutElement(pSArray, &l, &inqReport[l]); *ret = pSArray; return S_OK; }
标签:des style blog http color io os 使用 ar
原文地址:http://blog.csdn.net/xiaobin_hlj80/article/details/40162733