Reputation:
SAFEARRAYBOUND bound[1] = {25, 0};
SAFEARRAY * psa = SafeArrayCreate(VT_UI1, 1, bound);
for(long int i = 0; i <25; i++)
SafeArrayPutElement(psa, &i,sendBuf[i]);
I am trying to creating a safearray from a char array but get this error cannot convert from char to void*
sendBuf is a char array
Upvotes: 0
Views: 1482
Reputation: 596236
It would be more efficient in this case to use SafeArrayAccessData()
instead of SafeArrayPutElement()
:
SAFEARRAYBOUND bound[1] = {25, 0};
SAFEARRAY * psa = SafeArrayCreate(VT_UI1, 1, bound);
void *pvData;
SafeArrayAccessData(psa, &pvData);
memcpy(pvData, sendBuf, 25);
SafeArrayUnaccessData(psa);
Or:
SAFEARRAYBOUND bound[1] = {25, 0};
SAFEARRAY * psa = SafeArrayCreate(VT_UI1, 1, bound);
unsigned char *pvData;
SafeArrayAccessData(psa, (void**)&pvData);
for(long int i = 0; i <25; i++)
pvData[i] = sendBuf[i];
SafeArrayUnaccessData(psa);
Upvotes: 1
Reputation: 47962
You didn't show us the error, but it appears SafeArrayPutElement
takes a pointer to the element as the third parameter. I believe it'll work if you use:
SafeArrayPutElement(psa, &i, &sendBuf[i]);
Note the &
.
Upvotes: 3